public ActionResult <ItemReadDto> GetItemById(int id) { var item = _repository.GetItemById(id); if (item != null) { return(Ok(_mapper.Map <ItemReadDto>(item))); } else { _logger.LogWarning("Item with ID: {id} was not found", id); return(NotFound()); } }
public ActionResult <ExpireReadDto> CreateExpire(ExpireCreateDto expireCreateDto) { var model = new Expire() { ExpirationDate = expireCreateDto.ExpirationDate.Date, IdUser = _repository.GetUserById(expireCreateDto.UserId), IdItem = _repository.GetItemById(expireCreateDto.IdItem), IdStorage = _repository.GetStorageById(expireCreateDto.IdStorage), }; _repository.CreateExpire(model); _repository.SaveChanges(); var readDto = _mapper.Map <ExpireReadDto>(model); return(CreatedAtRoute(nameof(GetExpireById), new { Id = readDto.ExpireId }, readDto)); }