/// <summary> /// adds a new item /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <AlpApiResponse> AddNewItem(ItemDto dto) { var response = new AlpApiResponse(); try { _logger.LogDebug(new { action = nameof(AddNewItem), dto = dto?.ToString() }.ToString()); dto.Validate(); await CheckIfDuplicateAsync(dto); var entity = dto.DtoToEntity(); entity.Building = null; entity.Floor = null; entity.ItemNature = null; entity.ItemState = null; entity.ItemType = null; entity.Department = null; entity.Employee = null; entity.Section = null; entity.DateOfCreation = DateTime.Now; await _context.Item.AddAsync(entity); await _context.SaveChangesAsync(); } catch (Exception e) { _logger.LogError(new { exception = e, message = e.Message, innerException = e, innerExceptionMessage = e.InnerException?.Message }.ToString()); response.Message = e.Message; response.Success = false; } return(response); }