Example #1
0
        public IActionResult NewType()
        {
            NewTypeView model = new NewTypeView();

            model.Type = new CalendarItemType();

            return(View(model));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }