public IActionResult Edit(int id) { var model = new EditCalendarEntry(); if (!_authorizationService.CanUserModifyCalendarEntry(UserId, id)) { Unauthorized(); } model.Item = _calendarService.GetCalendarItemById(id); 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); model.StartTime = model.Item.Start.TimeConverter(department); model.EndTime = model.Item.End.TimeConverter(department); var recurrences = _calendarService.GetAllV2CalendarItemRecurrences(model.Item.CalendarItemId); if (recurrences != null && recurrences.Any()) { model.IsRecurrenceParent = true; } ViewBag.Types = new SelectList(model.Types, "CalendarItemTypeId", "Name"); model.Item.Description = StringHelpers.StripHtmlTagsCharArray(model.Item.Description); return(View(model)); }
public IActionResult Edit(EditCalendarEntry 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.Start = model.StartTime; model.Item.End = model.EndTime; model.Item.DepartmentId = DepartmentId; model.Item.CreatorUserId = UserId; model.Item.Entities = model.entities; _calendarService.UpdateV2CalendarItem(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)); ViewBag.Types = new SelectList(model.Types, "CalendarItemTypeId", "Name"); return(View(model)); }