public IActionResult ScheduleEvent([FromBody] ScheduleCalendarEventDto scheduleCalendarEventDto)
        {
            if (scheduleCalendarEventDto == null)
            {
                return(BadRequest());
            }

            var eventEntityMap = Mapper.Map <CalendarEvent>(scheduleCalendarEventDto);

            _calendarRepository.AddEvent(eventEntityMap);
            if (!_calendarRepository.Save())
            {
                throw new Exception("Failed to create event on save.");
            }
            return(CreatedAtRoute(routeName: "GetEvent", routeValues: new { id = eventEntityMap.Id }, value: eventEntityMap));
        }
Пример #2
0
        public IActionResult ScheduleNewEvent(ScheduleCalendarEventDto scheduleCalendarEventDto)
        {
            if (!ModelState.IsValid)
            {
                return(View(scheduleCalendarEventDto));
            }

            var mappedCalendarEvent = Mapper.Map <CalendarEvent>(scheduleCalendarEventDto);

            _calendarEventRepository.AddEvent(mappedCalendarEvent);

            if (!_calendarEventRepository.Save())
            {
                return(View(scheduleCalendarEventDto));
            }

            return(RedirectToAction("Week", "Calendar"));
        }