Exemplo n.º 1
0
        public CustomResult Create(CreateWorkingHourDto dto)
        {
            var result = CheckFilters(dto.FromTime, dto.ToTime, dto.MealTimeBreakFromTime
                                      , dto.MealTimeBreakToTime, dto.Break1FromTime, dto.Break1ToTime
                                      , dto.Break2FromTime, dto.Break2ToTime, dto.Break3FromTime, dto.Break3ToTime
                                      , dto.WorkingHourDuration);

            if (!result.IsValid)
            {
                return(result);
            }

            var workingHour = new WorkingHour
            {
                ShiftId               = dto.ShiftId,
                Title                 = dto.Title,
                FromTime              = dto.FromTime,
                ToTime                = dto.ToTime,
                WorkingHourDuration   = dto.WorkingHourDuration,
                DailyDelay            = dto.DailyDelay.GetSecondsFromDuration(),
                MonthlyDelay          = dto.MonthlyDelay.GetSecondsFromDuration(),
                DailyRush             = dto.DailyRush.GetSecondsFromDuration(),
                MonthlyRush           = dto.MonthlyRush.GetSecondsFromDuration(),
                PriorExtraWorkTime    = dto.PriorExtraWorkTime.GetSecondsFromDuration(),
                LaterExtraWorkTime    = dto.LaterExtraWorkTime.GetSecondsFromDuration(),
                FloatingTime          = dto.FloatingTime.GetSecondsFromDuration(),
                MealTimeBreakFromTime = dto.MealTimeBreakFromTime,
                MealTimeBreakToTime   = dto.MealTimeBreakToTime,
                Break1FromTime        = dto.Break1FromTime,
                Break1ToTime          = dto.Break1ToTime,
                Break2FromTime        = dto.Break2FromTime,
                Break2ToTime          = dto.Break2ToTime,
                Break3FromTime        = dto.Break3FromTime,
                Break3ToTime          = dto.Break3ToTime
            };

            _workingHourRepository.Insert(workingHour);

            return(new CustomResult
            {
                IsValid = true
            });
        }
        public IHttpActionResult Create([FromBody] CreateWorkingHourDto workingHour)
        {
            if (workingHour == null)
            {
                return(BadRequest());
            }
            //custom validations
            var validator = new CreateWorkingHourDtoValidator();
            var results   = validator.Validate(workingHour);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage);
                }
            }
            if (!ModelState.IsValid)
            {
                string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
                return(BadRequest(errorMessage));
            }
            try
            {
                var result = _workingHourService.Create(workingHour);
                if (!result.IsValid)
                {
                    return(BadRequest(result.Message));
                }
                return(Ok());
            }
            catch (LogicalException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
            }
        }