public ActionResult Create(FormCollection collection, Event Event, string Upload) { MembershipUser mu = Membership.GetUser(); try { ValidateEvent(Event); if (!ModelState.IsValid) { throw new Exception();//ModelState["Event.StartDateTime"].Errors.Last().ErrorMessage); } ImageController ac = new ImageController(); List <UploadFile> uploadFiles = ac.GenerateAttachFileCollectionID(collection, "Event"); if (Upload != null) { ImageUploadToServer(); if (uploadFiles != null) { ModelStateSetting(uploadFiles, "Event"); } var viewModel = new EventViewModel() { Event = Event, Locations = _entities.Locations.ToList(), EventTypes = (from r in _entities.EventTypes where r.ID != 2 && r.ID != 3 select r).ToList(), }; return(View(viewModel)); } foreach (UploadFile uploadFile in uploadFiles) { EventUploadFile auf = new EventUploadFile(); auf.UploadFileID = uploadFile.ID; Event.EventUploadFiles.Add(auf); } Event.OrganizerNameID = (Guid)(mu.ProviderUserKey); //GenerateEventPrices(Event); _entities.AddToEvents(Event); _entities.SaveChanges(); if (Event.EventTypeID == 1) { Event = (from r in _entities.Events select r).OrderByDescending(x => x.ID).First(); TempData["Event"] = Event; return(RedirectToAction("ScheduleModelSelect", "EventSchedule")); } else { EventScheduleController esc = new EventScheduleController(); esc.GenerateEventSchedules(Event); return(RedirectToAction("Index")); } } catch { var viewModel = new EventViewModel() { Event = new Event(), Locations = _entities.Locations.ToList(), EventTypes = (from r in _entities.EventTypes where r.ID != 2 && r.ID != 3 select r).ToList(), }; //viewModel.LocalRetreatScheduleModelSelectLists = GetScheduleSelectLists(); return(View(viewModel)); } }