public ActionResult Department() { var model = new DepartmentViewModel(); PrepareDepartmentViewModel(model); return View(model); }
private void PrepareDepartmentViewModel(DepartmentViewModel model) { model. Departments = _accountService.Departments.Select( s => new SelectListItem() { Text = s.Name, Value = s.Id.ToString(CultureInfo.InvariantCulture) }) .ToList(); model.Departments.Insert(0, new SelectListItem() { Text = "-", Value = "" }); }
public async Task<ActionResult> Department(DepartmentViewModel model) { if (ModelState.IsValid) { _accountService.AddDepartment(new Department() { Address = model.Address, ParentId = model.ParentDepartmentId, Name = model.Name }); } PrepareDepartmentViewModel(model); // If we got this far, something failed, redisplay form return View(model); }