public ActionResult CreateOrUpdate() { var trashCollector = Service.GetInformationByUserId(User.Identity.GetUserId()); if (trashCollector != null) { ViewBag.Title = "Edit information"; var trashCollectorViewModel = new TrashCollectorViewModel { Id = trashCollector.Id, StartTime = trashCollector.StartTime, EndTime = trashCollector.EndTime, WeekDays = trashCollector.WeekDays?.Split(','), ZipCodes = trashCollector.ZipCodes, MonthlyPayment = trashCollector.MonthlyPayment, UserId = trashCollector.UserId }; ViewBag.Title = "Edit information"; return(this.View(trashCollectorViewModel)); } ViewBag.Title = "Add information"; return(View(new TrashCollectorViewModel())); }
public ActionResult CreateOrUpdate(TrashCollectorViewModel model) { if (!ModelState.IsValid) { return(View("CreateOrUpdate", model)); } model.UserId = User.Identity.GetUserId(); Service.CreateOrUpdate(model.ToDomainObject()); return(RedirectToAction("Index", "Home")); }