Example #1
0
        public async Task <ActionResult <HolidayModel> > Put(int employeeId, int Id, HolidayModel updatedModel)
        {
            try
            {
                var currentHoliday = await _repository.GetHolidayAsync(employeeId, Id);

                if (currentHoliday == null)
                {
                    return(NotFound($"Could not find Holiday with Id of {Id}"));
                }

                _mapper.Map(updatedModel, currentHoliday);

                if (await _repository.UpdateHolidayAsync(employeeId, currentHoliday))
                {
                    return(_mapper.Map <HolidayModel>(currentHoliday));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }