Telerik scheduler appointments in different colors - telerik

I'm reading the appointments form a datatable. Here is my code:
List<MyClass> myObjects = (from e in myEntities.Mytable where
e.DateFrom >= schedulerInfo.ViewStart &&
e.DateTo <= schedulerInfo.ViewEnd
select e).ToList();
List<Appointment> appointments = new List<Appointment>(myObjects.Count);
foreach (MyClass e in myObjects) {
Appointment a = new Appointment();
a.ID = e.ID;
a.Subject = e.Description;
a.Start = e.DateFrom;
a.End = e.DateTo;
a.BackColor = System.Drawing.Color.Yellow;
appointments.Add(a);
and when I run it, it isn't yellow!

In order to change the color of an appointment in the RadScheduler you will have to subscribe to the OnAppointmentDataBound event. As can be seen in this documentation article, all you have to do is grab the current appointment objects from e.Appointment and define the BackColor (and other available properties) and you should be all set!

Related

Dynamics CRM Linq Update multiple records

Trying to update a list of Incident records. The first one in the foreach updates, the next one throws an exception stating "the context is not currently tracking the incident entity". Is this the correct way to code this?
var openCases = (from o in xrmContext.IncidentSet
where o.StateCode == 0
select o).Take(5).ToList();
foreach (var c in openCases)
{
var numDays = ((TimeSpan) (DateTime.Now - c.CreatedOn)).Days;
Console.WriteLine("case age: {0}, case number:{1}", numDays, c.TicketNumber);
c.new_caseage = numDays;
xrmContext.UpdateObject(c);
xrmContext.SaveChanges();
}
When you call SaveChanges() it, in addition to saving any modified entity records, detaches all entity records being tracked in the context. Therefore, the second time you call SaveChanges() the entity record is not being tracked and you receive the error.
You should move the xrmContext.SaveChanges(); line to be after the foreach loop.
var openCases = (from o in xrmContext.IncidentSet
where o.StateCode == 0
select o).Take(5).ToList();
foreach (var c in openCases)
{
var numDays = ((TimeSpan) (DateTime.Now - c.CreatedOn)).Days;
Console.WriteLine("case age: {0}, case number:{1}", numDays, c.TicketNumber);
c.new_caseage = numDays;
xrmContext.UpdateObject(c);
}
xrmContext.SaveChanges();
All entities are detached by the OrganizationServiceContext after calling the SaveChanges method. To continue using the data context against previously retrieved entities, the entities need to be reattached.
However, the preference is to apply all modifications under a single call to SaveChanges, and then dispose the context, to avoid the need to reattach.
http://msdn.microsoft.com/en-us/library/gg695783.aspx
http://msdn.microsoft.com/en-us/library/gg334504.aspx#track_related
A better way to do what your try to do is using the message ExecuteMultipleRequest, with it can configure how many record to process for every iteration (internal iteration)
var openCases = (from o in xrmContext.IncidentSet
where o.StateCode == 0
select o).Take(5).ToList();
var requestWithResults = new ExecuteMultipleRequest()
{
// Assign settings that define execution behavior: continue on error, return responses.
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = false,
ReturnResponses = true
},
// Create an empty organization request collection.
Requests = new OrganizationRequestCollection()
};
foreach (var c in openCases)
{
var numDays = ((TimeSpan) (DateTime.Now - c.CreatedOn)).Days;
c.new_caseage = numDays;
CreateRequest createRequest = new CreateRequest { Target = c };
requestWithResults.Requests.Add(createRequest);
}
ExecuteMultipleResponse responseWithResults =
(ExecuteMultipleResponse)_serviceProxy.Execute(requestWithResults);
Hope it helps

Linq join - add result to property

I have an Alert class, with for example 10 properties. Two of the properties are [NotMapped] -
Then in my controller, I'm using Linq to join two tables to get the Alert class and a Customer class.
From the Customer class, there are two properties (customerName and customerAdmin) that I want to assign to the Alert class.
At the moment I'm doing this.....
var Alerts = (from a in alertrepository.Alerts
join code..........
Alerts = a
Customer = b
.................
select new Alert {
alertID = a.alertID,
applicantName = a.applicantName,
applicantEmail = a.applicantEmail,
applicantTelephone = a.applicantTelephone,
location = a.location,
dateSubmitted = a.dateSubmitted,
This - alertCustomerName= b.customerName,
This - alertCustomerAdmin= b.customerAdmin,
}).ToList();
Instead of having to declare a new Alert class again, and manually fill every property again as I am doing, is there any quicker way just to add individual properties?
For example, select a { a.alertCustomerName = b.customerName etc}

Issue To Select/Show DropDown Selected Value At Edit() In Asp.net MVC 3

I Using Two Table User And Location In User Table I having LocationId And When I'm going to edit The User Form Then I need User With There Exact Location In Drop Down.but i didn't get that this is my code Of Controller:-
LogisticsEntities db = new LogisticsEntities();
RegisterModel Reg = new RegisterModel();
var tempUser = (from c in db.Users select new RegisterModel { _UserId = c.UserID, UserName = c.Name, Code = c.Code, Email = c.Email, Phone = c.Phone, JobRole = c.JobRole, StartDate = c.StartDate, EndDate = c.EndDate, LocationId = c.Location }).SingleOrDefault(x => x._UserId == id);
var varLocation = from Ls in db.Locations select Ls;
ViewData["LocationId"] = new SelectList(varLocation.ToList(), "LocationID", "Location1", "2");
if (tempUser != null)
return View(tempUser);
else
return View();
And In My View I Have code: -
#Html.DropDownList("LocationID", (SelectList)ViewData["LocationId"])
Thanx In Advance..
You are using LocationID as both first parameter of the dropdown and inside ViewData. In order to generate a dropdown you need 2 things: the first argument will be used to generate the name attribute of the dropdown and used to bind the value back and the second argument must represent a collection of SelectListItem that will be used to create the options of the dropdown. So try using a different key for the collection:
ViewData["locations"] = new SelectList(varLocation.ToList(), "LocationID", "Location1", "2");
and then:
#Html.DropDownList("LocationID", (SelectList)ViewData["locations"])

Create ViewModel using multiple models

Build ViewModel using two models
Model 1: Person (Id,Name,Address,Phone,CategoryId)
Model 2: Category(CategoryId,CategoryText)
ViewModel: PersonViewModel (Name,Phone, CategoryText)
Question: how would I generate my ViewModel in my controller and forward it to the view:
var model = (from x in db.Person
select new PersonViewModel {
Name = x.Name,
Phone = x.Phone,
CategoryText = ??? }).ToList();
How do I generate CategoryText?
Thanks
You need to join on categories.
you may be able to include as the following, if not you just need a join. Try the following (I forget if you can include() in this syntax - somethingin my mind tells me you can't and if that's the case I'll delete this shortly as I see someone just posted the join syntax)
var model = (from x in db.Person.Include(o=>o.Category) //assumes EF 4.1 if not try .Include("Category")
select new PersonViewModel {
Name = x.Name,
Phone = x.Phone,
CategoryText = x.Category.CategoryText }).ToList();
var model = (from x in db.Person
join y from db.Category on x.CategoryId equals y.CategoryID
select new PersonViewModel {
Name = x.Name,
Phone = x.Phone,
CategoryText = y.CategoryText }).ToList();

Linq: How to load a second table directly?

I have 2 tables here:
Auction and Article.
1 Auction has 1 Article.
1 Aricle has x Auctions.
Now I load a list of auctions:
using (APlattformDatabaseDataContext dc = new APlattformDatabaseDataContext())
{
List<Auktion> auctionlist = (from a in dc.Auktion
where a.KäuferID == null
select a).ToList();
return auctionlist;
}
But when I want to "txtBla.Text = auction[0].Article.Text;" it isn't loaded.
The question isn't why (it is logic that it isn't loaded allready and can't be loaded because the DC is closed), but how can I solve this without letting the DC open?
You can do the following:
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<Auktion>(a => a.Article);
dc.LoadOptions = options;
If you want to eager load the associations like that you should use the DataContext.LoadOptions property like so...
using (APlattformDatabaseDataContext dc = new APlattformDatabaseDataContext())
{
var dlo = new DataLoadOptions();
options.LoadWith<Auktion>(o => o.Article);
dc.LoadOptions = dlo;
List<Auktion> auctionlist = (from a in dc.Auktion
where a.KäuferID == null
select a).ToList();
return auctionlist;
}
That way your articles will be loaded when your Auktion objects are retrieved from the database.

Resources