public async Task <ForestPlotDetailDto> UpdateForestPlotsAsync(EditForestPlotDto dto) { //ValidateActorDto(dto); var forestPlotToUpdate = await _unitOfWork.GetRepository <ICForestPlot>().GetAsync(dto.Id); var actor = await _unitOfWork.GetRepository <APActor>().GetAsync(dto.FK_APActorID.Value); dto.APActorCode = actor.APActorCode; var treeSpecies = await _unitOfWork.GetRepository <ICTreeSpec>().GetAsync(dto.FK_ICTreeSpecID.Value); dto.ICTreeSpecCode = treeSpecies.ICTreeSpecCode; var landUseCert = await _unitOfWork.GetRepository <ICLandUseCert>().GetAsync(dto.FK_ICLandUseCertID.Value); dto.ICLandUseCertCode = landUseCert.ICLandUseCertCode; //var forestPlotHistory = await _unitOfWork.GetRepository<ICForestPlotHistory>() // .GetAll() // .WhereIf(forestPlotToUpdate.Id > 0, x => x.FK_ICForestPlotID == forestPlotToUpdate.Id) // .WhereIf(forestPlotToUpdate.FK_APActorID > 0, x => x.FK_APActorID == forestPlotToUpdate.FK_APActorID) // .WhereIf(forestPlotToUpdate.FK_ICForestCertID > 0, x => x.FK_ICForestCertID == forestPlotToUpdate.FK_ICForestCertID) // .WhereIf(forestPlotToUpdate.FK_ICLandUseCertID > 0, x => x.FK_ICLandUseCertID == forestPlotToUpdate.FK_ICLandUseCertID) // .WhereIf(forestPlotToUpdate.FK_ICTreeSpecID > 0, x => x.FK_ICTreeSpecID == forestPlotToUpdate.FK_ICTreeSpecID) // .WhereIf(!forestPlotToUpdate.ICForestPlotReliability.IsNullOrEmpty(), x => x.ICForestPlotHistoryReliability == forestPlotToUpdate.ICForestPlotReliability) // .WhereIf(forestPlotToUpdate.ICForestPlotPlantingDate.HasValue, x => x.ICForestPlotHistoryPlantingDate == forestPlotToUpdate.ICForestPlotPlantingDate) // .WhereIf(!forestPlotToUpdate.ICConflictSitCode.IsNullOrEmpty(), x => x.ICConflictSitCode == forestPlotToUpdate.ICConflictSitCode).FirstOrDefaultAsync(); if ((forestPlotToUpdate.APActorCode != dto.APActorCode) || (forestPlotToUpdate.FK_APActorID != dto.FK_APActorID) || (forestPlotToUpdate.FK_ICTreeSpecID != dto.FK_ICTreeSpecID) || (forestPlotToUpdate.ICTreeSpecCode != dto.ICTreeSpecCode) || (forestPlotToUpdate.ICForestPlotPlantingDate.GetValueOrDefault().Date != Convert.ToDateTime(dto.ICForestPlotPlantingDate).Date) || (forestPlotToUpdate.ICForestPlotReliability != dto.ICForestPlotReliability) || (forestPlotToUpdate.ICConflictSitCode != dto.ICConflictSitCode) || (forestPlotToUpdate.FK_ICLandUseCertID != dto.FK_ICLandUseCertID) || (forestPlotToUpdate.FK_ICForestCertID != dto.FK_ICForestCertID) || (forestPlotToUpdate.ICLandUseCertCode != dto.ICLandUseCertCode) || (forestPlotToUpdate.ICForestPlotArea != dto.ICForestPlotArea) || (forestPlotToUpdate.ICForestPlotVolumnPerPlot != dto.ICForestPlotVolumnPerPlot) ) { await CreateForestPlotHistoryAsync(forestPlotToUpdate); } UpdateForestPlotDto(forestPlotToUpdate, dto); await _forestPlotRepository.UpdateAsync(forestPlotToUpdate); await _unitOfWork.CompleteAsync(); return(await GetUserAsync(forestPlotToUpdate.Id)); }
private static void UpdateForestPlotDto(ICForestPlot entity, EditForestPlotDto dto) { if (entity == null) { throw new EntityNotFoundException(); } entity.APActorCode = dto.APActorCode; entity.FK_APActorID = dto.FK_APActorID; entity.FK_ICTreeSpecID = dto.FK_ICTreeSpecID; entity.ICTreeSpecCode = dto.ICTreeSpecCode; entity.ICForestPlotPlantingDate = Convert.ToDateTime(dto.ICForestPlotPlantingDate); entity.ICForestPlotPlantingYear = entity.ICForestPlotPlantingDate.GetValueOrDefault().Year; entity.ICForestPlotReliability = dto.ICForestPlotReliability; entity.ICConflictSitCode = dto.ICConflictSitCode; entity.FK_ICLandUseCertID = dto.FK_ICLandUseCertID; entity.FK_ICForestCertID = dto.FK_ICForestCertID; entity.ICLandUseCertCode = dto.ICLandUseCertCode; entity.ICForestPlotArea = dto.ICForestPlotArea; entity.ICForestPlotVolumnPerPlot = dto.ICForestPlotVolumnPerPlot; }
public async Task <IActionResult> Update([FromBody] EditForestPlotDto dto) { var result = await _forestPlotService.UpdateForestPlotsAsync(dto); return(Success(result)); }