Can't save CalendarEvents with a user id?

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]

I just tried setting up another controller and save works perfectly with this code:

[code]// POST: /CalendarEvent/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task Create([Bind(Include=“id,text,start_date,end_date”)] CalendarEvent calendarevent)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
calendarevent.ApplicationUser = currentUser;
db.CalendarEvents.Add(calendarevent);
await db.SaveChangesAsync();
return RedirectToAction(“Index”);
}

        return View(calendarevent);
    }[/code]

What would cause the calendar controller to function so differently? It’s fundamentally the same thing?

Hi,
Was there an exception during saving? If so, what was the error message?