public async Task <ApiResult <bool> > InsertPlantingAction(PlantingAction plantingAction) { if (plantingAction == null) { _logger.LogError("plantingAction is null"); return(new ApiResult <bool> { ApiCode = ApiCode.NullObject, ErrorMessage = "plantingAction is null", Result = false }); } _logger.LogInformation($"Planting action to insert: {JsonConvert.SerializeObject(plantingAction)}"); plantingAction.CreatedAt = DateTime.UtcNow; var result = await _unitOfWork.PlantingActionRepository.Insert(plantingAction); return(new ApiResult <bool> { ApiCode = ApiCode.Success, Result = result }); }
public async Task <ApiResult <bool> > UpdatePlantingAction(int id, PlantingAction plantingAction) { try { var stopwatch = Stopwatch.StartNew(); _logger.LogInformation("Update plantingAction"); plantingAction.Id = id; var result = await _plantingProcessService.UpdatePlantingAction(plantingAction); _logger.LogInformation("Update plantingAction complete"); stopwatch.Stop(); result.ExecutionTime = stopwatch.Elapsed.TotalMilliseconds; _logger.LogInformation($"Execution time: {result.ExecutionTime}ms"); return(result); } catch (Exception ex) { _logger.LogInformation($"Update plantingAction error: {ex}"); return(new ApiResult <bool> { Result = false, ApiCode = ApiCode.UnknownError, ErrorMessage = ex.ToString() }); } }
public async Task <ApiResult <bool> > UpdatePlantingAction(PlantingAction plantingAction) { if (plantingAction == null) { _logger.LogError("plantingAction is null"); return(new ApiResult <bool> { ApiCode = ApiCode.NullObject, ErrorMessage = "plantingProcess inputted is null", Result = false }); } _logger.LogInformation($"plantingAction to update: {JsonConvert.SerializeObject(plantingAction)}"); var existing = await _unitOfWork.PlantingActionRepository.GetFirstOrDefault(x => x.Id == plantingAction.Id); if (existing == null) { _logger.LogError($"plantingAction not found with id: {plantingAction.Id}"); return(new ApiResult <bool> { ApiCode = ApiCode.NotFound, ErrorMessage = $"plantingAction not found with id: {plantingAction.Id}", Result = false }); } existing.Description = plantingAction.Description; existing.ActionTime = plantingAction.ActionTime; existing.Amount = plantingAction.Amount; existing.Name = plantingAction.Name; existing.Status = plantingAction.Status; var result = await _unitOfWork.PlantingActionRepository.Update(existing); return(new ApiResult <bool> { Result = result, ApiCode = ApiCode.Success }); }