public ActionResult New(CreateEventViewModel model) { UserModel um = accountServices.GetUserByUsername(User.Identity.Name); CreateEventModel cem = new CreateEventModel(); cem.Address = model.Address; cem.CategoryString = model.CategoryString; cem.Description = model.Description; cem.EndTime = DateTime.Parse(model.EndMonth + "/" + model.EndDay + "/" + model.EndYear + " " + model.EndHour + ":" + model.EndMinute + " " + model.EndAMPM); cem.Latitude = model.Latitude; cem.Longitude = model.Longitude; cem.StartTime = DateTime.Parse(model.StartMonth + "/" + model.StartDay + "/" + model.StartYear + " " + model.StartHour + ":" + model.StartMinute + " " + model.StartAMPM); cem.Title = model.Title; string username = User.Identity.Name; cem.UserProfileId = accountServices.GetUserProfileByUsername(username).UserProfileId; try { eventServices.CreateEvent(cem); } catch (ConstraintException e) { ViewData["message"] = e.Message; if (e.Data.Contains("Entity")) { ViewData["message"] = e.Data["Entity"] + " cannot be left blank!"; } ProfileController.SetViewDataForDate(ViewData); ProfileController.SetViewDataForTime(ViewData); return View(model); } return Redirect("/"); }
public ActionResult New() { UserModel um = accountServices.GetUserByUsername(User.Identity.Name); CreateEventViewModel model = new CreateEventViewModel(); model.Title = ""; model.CreateTime = DateTime.Now; model.DeleteTime = DateTime.Now; ProfileController.SetViewDataForDate(ViewData); ProfileController.SetViewDataForTime(ViewData); return View(model); }