Beispiel #1
0
        public IHttpActionResult PostSchedules(int offeringId, [FromBody] ScheduleListDto form)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var schedules = Mapper.Map <IEnumerable <ScheduleDto>, IEnumerable <Schedule> >(form.Schedules);
                    var offering  = _offeringService.Get(offeringId);

                    _scheduleService.AddRange(schedules);

                    var scheduleListDto = GetScheduleListDto(offeringId, offering, schedules);

                    return(Created(new Uri(scheduleListDto.Url), scheduleListDto));
                }
                catch (ArgumentException ae)
                {
                    ModelState.AddModelError("", ae.Message);
                }
                catch (PreexistingEntityException pee)
                {
                    ModelState.AddModelError("", pee.Message);
                }
            }

            return(BadRequest(ModelState));
        }