public IHttpActionResult Create([FromBody] CreatePersonnelHourlyShiftDto personnelHourlyShift)
 {
     if (personnelHourlyShift == null)
     {
         return(BadRequest());
     }
     if (!ModelState.IsValid)
     {
         string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState);
         return(BadRequest(errorMessage));
     }
     try
     {
         var result = _personnelShiftService.Create(personnelHourlyShift);
         if (!result.IsValid)
         {
             return(BadRequest(result.Message));
         }
     }
     catch (LogicalException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch
     {
         return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE));
     }
     return(Ok());
 }
        public CustomResult Create(CreatePersonnelHourlyShiftDto dto)
        {
            if (dto.PersonnelIdList.Count == 0)
            {
                return(new CustomResult
                {
                    Message = "please choose personnel"
                });
            }

            foreach (var personnelId in dto.PersonnelIdList)
            {
                if (HasNormalShift(personnelId))
                {
                    var person = _personnelRepository.GetById(personnelId);
                    return(new CustomResult
                    {
                        Message = $"for person: {person.Name + " " + person.LastName}" +
                                  $" normal shift has been assigned. cannot add hourly shift. request rejected"
                    });
                }
                if (SameShiftForSameDayExists(personnelId, dto.HourlyShiftId))
                {
                    return(new CustomResult
                    {
                        Message = "cannot add the same shift for the same day"
                    });
                }

                var personnelHourlyShift = new PersonnelHourlyShift
                {
                    PersonnelId   = personnelId,
                    HourlyShiftId = dto.HourlyShiftId,
                    DateAssigned  = DateTime.Now
                };
                _personnelHourlyShiftRepository.Insert(personnelHourlyShift);
            }

            return(new CustomResult
            {
                IsValid = true
            });
        }