public IActionResult New() { var model = new NewCalendarEntry(); model.Item = new CalendarItem(); model.Types = new List <CalendarItemType>(); model.Types.Add(new CalendarItemType() { CalendarItemTypeId = 0, Name = "No Type" }); model.Types.AddRange(_calendarService.GetAllCalendarItemTypesForDepartment(DepartmentId)); var department = _departmentsService.GetDepartmentById(DepartmentId); var currentTime = DateTime.UtcNow.TimeConverter(department); model.Item.Start = currentTime.AddHours(3); model.Item.End = currentTime.AddHours(4); ViewBag.Types = new SelectList(model.Types, "CalendarItemTypeId", "Name"); return(View(model)); }
public IActionResult New(NewCalendarEntry model) { if (model.Item.Start > model.Item.End) { ModelState.AddModelError("Item_End", "End date and time cannot be before start date and time."); } if ((model.Item.RecurrenceType == (int)RecurrenceTypes.Weekly || model.Item.RecurrenceType == (int)RecurrenceTypes.Monthly || model.Item.RecurrenceType == (int)RecurrenceTypes.Yearly) && (model.Item.RecurrenceEnd.HasValue && (model.Item.RecurrenceEnd.Value <= model.Item.Start || model.Item.RecurrenceEnd.Value <= model.Item.End))) { ModelState.AddModelError("Item_End", "End date and time cannot be before start date and time."); } if (ModelState.IsValid) { var department = _departmentsService.GetDepartmentById(DepartmentId); model.Item.DepartmentId = DepartmentId; model.Item.CreatorUserId = UserId; model.Item.Entities = model.entities; _calendarService.AddNewV2CalendarItem(model.Item, department.TimeZone); return(RedirectToAction("Index")); } model.Types = new List <CalendarItemType>(); model.Types.Add(new CalendarItemType() { CalendarItemTypeId = 0, Name = "No Type" }); model.Types.AddRange(_calendarService.GetAllCalendarItemTypesForDepartment(DepartmentId)); model.Item.Description = StringHelpers.StripHtmlTagsCharArray(model.Item.Description); return(View(model)); }