Example #1
0
        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));
        }