示例#1
0
 public IHttpActionResult Create([FromBody] CreateHourlyShiftDto hourlyShift)
 {
     if (hourlyShift == null)
     {
         return(BadRequest());
     }
     if (!ModelState.IsValid)
     {
         string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
         return(BadRequest(errorMessage));
     }
     try
     {
         _hourlyShiftService.Create(hourlyShift);
     }
     catch (LogicalException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
     }
     return(Ok());
 }
        public void Create(CreateHourlyShiftDto dto)
        {
            var hourlyShift = new HourlyShift
            {
                Title = dto.Title,
                HoursShouldWorkInDay = dto.HoursShouldWorkInDay.HasValue
                    ? (int?)dto.HoursShouldWorkInDay.Value.GetHoursInSeconds() : null,
                HoursShouldWorkInWeek = dto.HoursShouldWorkInWeek.HasValue
                    ? (int?)dto.HoursShouldWorkInWeek.Value.GetHoursInSeconds() : null,
                HoursShouldWorkInMonth = dto.HoursShouldWorkInMonth.HasValue
                    ? (int?)dto.HoursShouldWorkInMonth.Value.GetHoursInSeconds() : null
            };

            _shiftRepository.Insert(hourlyShift);
        }