Ejemplo n.º 1
0
 public IHttpActionResult Update([FromBody] UpdateHourlyShiftDto hourlyShift)
 {
     if (hourlyShift == null)
     {
         return(BadRequest());
     }
     if (!ModelState.IsValid)
     {
         string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
         return(BadRequest(errorMessage));
     }
     try
     {
         _hourlyShiftService.Update(hourlyShift);
     }
     catch (LogicalException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
     }
     return(Ok());
 }
        public void Update(UpdateHourlyShiftDto dto)
        {
            var hourlyShift = _shiftRepository.GetById(dto.Id);

            if (hourlyShift != null)
            {
                hourlyShift.Title = dto.Title;
                hourlyShift.HoursShouldWorkInDay = dto.HoursShouldWorkInDay.HasValue
                    ? (int?)dto.HoursShouldWorkInDay.Value.GetHoursInSeconds() : null;
                hourlyShift.HoursShouldWorkInWeek = dto.HoursShouldWorkInWeek.HasValue
                    ? (int?)dto.HoursShouldWorkInWeek.Value.GetHoursInSeconds() : null;
                hourlyShift.HoursShouldWorkInMonth = dto.HoursShouldWorkInMonth.HasValue
                    ? (int?)dto.HoursShouldWorkInMonth.Value.GetHoursInSeconds() : null;

                _shiftRepository.Update(hourlyShift);
            }
            else
            {
                try
                {
                    throw new LogicalException();
                }
                catch (LogicalException ex)
                {
                    _logger.LogLogicalError
                        (ex, "HourlyShift entity with the id: '{0}', is not available." +
                        " update operation failed.", dto.Id);
                    throw;
                }
            }
        }