public IActionResult NewType() { NewTypeView model = new NewTypeView(); model.Type = new CalendarItemType(); return(View(model)); }
public IActionResult NewType(NewTypeView model) { if (_calendarService.GetAllCalendarItemTypesForDepartment(DepartmentId).Any(x => x.Name == model.Type.Name)) { ModelState.AddModelError("", "Type name already exists, please choose another name."); } if (ModelState.IsValid) { model.Type.DepartmentId = DepartmentId; _calendarService.SaveCalendarItemType(model.Type); return(RedirectToAction("Types", "Calendar", new { Area = "User" })); } return(View(model)); }
public async Task <IActionResult> NewType(NewTypeView model, CancellationToken cancellationToken) { if ((await _calendarService.GetAllCalendarItemTypesForDepartmentAsync(DepartmentId)).Any(x => x.Name == model.Type.Name)) { ModelState.AddModelError("", "Type name already exists, please choose another name."); } if (ModelState.IsValid) { model.Type.DepartmentId = DepartmentId; await _calendarService.SaveCalendarItemTypeAsync(model.Type, cancellationToken); return(RedirectToAction("Types", "Calendar", new { Area = "User" })); } return(View(model)); }