/// <summary> /// updates itemstate by dto /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <AlpApiResponse> UpdateItemState(ItemStateDto dto) { var response = new AlpApiResponse(); try { _logger.LogDebug(new { action = nameof(UpdateItemState), dto = dto?.ToString() }.ToString()); dto.Validate(); if (dto.Id == 1 || dto.Id == 2 || dto.Id == 3) { response.Success = false; response.Message = "Ennek a státusznak az adatai nem változtathatóak!"; return(response); } var updatedEntity = await _context.ItemState.FirstOrDefaultAsync(itemState => itemState.ItemStateId == dto.Id); updatedEntity.UpdateEntityByDto(dto); 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); }
/// <summary> /// adds new itemstate /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <AlpApiResponse <ItemStateDto> > AddNewItemState(ItemStateDto dto) { var response = new AlpApiResponse <ItemStateDto>(); try { _logger.LogDebug(new { action = nameof(AddNewItemState), dto = dto?.ToString() }.ToString()); dto.Validate(); var entity = dto.DtoToEntity(); await _context.ItemState.AddAsync(entity); await _context.SaveChangesAsync(); response.Value = entity.EntityToDto(); } 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); }