// GET: Administration/Offices/Create public ActionResult Create() { NewOfficeViewModel model = new NewOfficeViewModel(); IEnumerable <SelectListItem> managers = this.GetManagers(); model.Managers = managers; return(View(model)); }
public ActionResult Create(NewOfficeViewModel model) { if (ModelState.IsValid) { ApplicationUser manager = this.data.Users.Find(model.ManagerId); if (manager == null) { this.TempData["ErrorMessage"] = "Invalid manager"; this.RedirectToAction("Index"); } Office office = new Office(); Mapper.Map(model, office); this.data.Offices.Add(office); this.data.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }