Hello,
I’m evaluating your scheduler product for potential purchase but I’m having trouble saving CalendarEvents with a user. If I don’t set the user, my controller saves the CalendarEvent without issue, if I do set the user, my controller stops at data.CalendarEvents.Add(CalendarEvent), I’ve tried both async and non-threaded methods. Update and delete also hang on their respective context.action methods. Any ideas?
Here is my controller code:
[code]public ContentResult Save(CalendarEvent updatedEvent, FormCollection formData)
{
var action = new DataAction(formData);
var context = new CPDbContext();
try
{
var currentUser = manager.FindById(User.Identity.GetUserId());
switch (action.Type)
{
case DataActionTypes.Insert: //insert case
//if (ModelState.IsValid)
//{
if(updatedEvent.id == 0)
{
context.CalendarEvents.Add(updatedEvent);
}
else
{
context.CalendarEvents.Attach(updatedEvent);
context.Entry(updatedEvent).State = EntityState.Modified;
}
updatedEvent.ApplicationUser = currentUser;
//}
if (!ModelState.IsValid)
{
var errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception));
// Breakpoint, Log or examine the list with Exceptions.
}
break;
case DataActionTypes.Delete: //delete case
updatedEvent = context.CalendarEvents.SingleOrDefault(ev => ev.id == updatedEvent.id);
context.CalendarEvents.Remove(updatedEvent);
break;
default: //update case
updatedEvent.ApplicationUser = currentUser;
updatedEvent = context.CalendarEvents.SingleOrDefault(
ev => ev.id == updatedEvent.id);
UpdateModel(updatedEvent);
break;
}
Console.Write("Getting it");
context.SaveChanges();
action.TargetId = updatedEvent.id;
}
catch (Exception e)
{
action.Type = DataActionTypes.Error;
}
return Content(new AjaxSaveResponse(action));
}[/code]
And this is my CalendarEvent class:
[code]public class CalendarEvent
{
//id, text, start_date and end_date properties are mandatory
public int id { get; set; }
public string text { get; set; }
public DateTime start_date { get; set; }
public DateTime end_date { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}[/code]