Пример #1
0
 public static ForestPlotDetailDto ToForestPlotDetailDto(this ICForestPlot entity)
 {
     return(entity == null
         ? null
         : new ForestPlotDetailDto
     {
         Id = entity.Id,
         Area = entity.ICForestPlotArea,
         PlantingYear = entity.ICForestPlotPlantingYear.GetValueOrDefault() == 0 ? 0 : (Clock.Now.Year - entity.ICForestPlotPlantingYear.GetValueOrDefault()),
         TreeSpec = entity.ICTreeSpec.ToTreeSpecDto(),
         CompartmentCode = entity.GECompartment?.GECompartmentCode,
         SubCompartmentCode = entity.GESubCompartment?.GESubCompartmentCode,
         PlotCode = entity.GEPlotCode,
         PlantingDate = entity.ICForestPlotPlantingDate.ToSecondsTimestamp(),
         //Dispute = entity.ICForestPlotDispute.ToDictionaryItemDto<ForestPlotDispute>(),
         Actor = entity.APActor.ToActorDto(),
         ActorType = entity.APActor?.APActorType.ToActorTypeDto(),
         Compartment = entity.GECompartment.ToDictionaryItemDto(),
         ForestCert = entity.ICForestCert.ToDictionaryItemDto(),
         Plot = null,     //TOdo mapping
         SubCompartment = entity.GESubCompartment.ToDictionaryItemDto(),
         VolumnPerPlot = entity.ICForestPlotVolumnPerPlot,
         Reliability = entity.ICForestPlotReliability.ToDictionaryItemDto <ForestPlotReliability>(),
         LandUseCert = entity.GEDisICLandUseCerttrict.ToDictionaryItemDto(),
         ConflictSitCode = Convert.ToInt32(entity.ICConflictSitCode),
         LocationLatitude = entity.ICForestPlotLocationLatitude,
         LocationLongitude = entity.ICForestPlotLocationLongitude,
     });
 }
Пример #2
0
 public static ActorDto ToActorDto(this ICForestPlot entity)
 {
     return entity == null
         ? null
         : new ActorDto
         {
             Id = entity.APActor.Id,
             Email = entity.APActor.APActorEmail,
             Phone = entity.APActor.APActorPhone,
             Name = entity.APActor.APActorName,
             Website = entity.APActor.APActorWebsite,
             Avatar = entity.APActor.APActorAvatar.ToImageUrl(),
             //AverageRating = entity.APActorReviews.IsNullOrEmpty() ? 0 : (decimal)entity.APActorReviews.Sum(x => x.APActorReviewRating) / entity.APActorReviews.Count,
             AverageRating = entity.APActorReviews.Where(o => o.FK_APActorID == entity.FK_APActorID).Count() > 0
             ? entity.APActorReviews.ToAverageRating(entity) : 5,
             AggregateOfRatings = entity.APActorReviews.Where(o => o.FK_APActorID == entity.FK_APActorID).ToArray().ToAggregateOfRatings(),
             Reviews = entity.APActorReviews.Where(o => o.FK_APActorID == entity.FK_APActorID).ConvertArray(x => x.ToReviewItemDto()),
             AcronymName = entity.APActor.APActorAcronymName,
             Address = entity.APActor.APActorAddress,
             Commune = entity.APActor.GECommune.ToDictionaryItemDto(),
             District = entity.GEDistrict.ToDictionaryItemDto(),
             Fax = entity.APActor.APActorFax,
             HouseNumber = entity.APActor.APActorHouseNumber,
             IdentityCard = entity.APActor.APActorIdentityCard,
             Representative = entity.APActor.APActorRepresentative,
             StateProvince = entity.GEStateProvince.ToDictionaryItemDto(),
             Type = entity.APActor.APActorType.ToActorTypeDto(),
             Roles = entity.APActor.APActorRoles.ConvertArray(x => x?.APRole.ToDictionaryItemDto()),
             Status = entity.APActor.APActorStatus.ToDictionaryItemDto<UserStatus>(),
             ForestPlot = entity.ToForestPlotDto(),
             ContactName = entity.APActor.APActorContactName,
             ContactPhone = entity.APActor.APActorContactPhone,
             Note = entity.APActor.APActorNote
         };
 }
Пример #3
0
 public static decimal ToAverageRating(this ICollection<APActorReview> list, ICForestPlot entity)
 {
     return list.IsNullOrEmpty()
         ? 0
         : (decimal)list.Where(o => o.FK_APActorID == entity.FK_APActorID)
               .Sum(x => x.APActorReviewRating)
           / (list.Where(o => o.FK_APActorID == entity.FK_APActorID).Count());
 }
Пример #4
0
        public async Task CreateForestPlotHistoryAsync(ICForestPlot dto)
        {
            var forestPlotHistoryCreate = dto.ToForestPlotHistory(_bysSession);
            await _unitOfWork.GetRepository <ICForestPlotHistory>().InsertAsync(forestPlotHistoryCreate);

            await _unitOfWork.CompleteAsync();

            //return await GetForestPlotHistoryAsync(forestPlotHistory.Id);
        }
Пример #5
0
 public static ICForestPlotHistory ToForestPlotHistory(this ICForestPlot entity, IBysSession session)
 {
     return(entity == null
         ? null
         : new ICForestPlotHistory
     {
         GEProvinceCode = entity.GEProvinceCode,
         GEDistrictCode = entity.GEDistrictCode,
         GECommuneCode = entity.GECommuneCode,
         GECompartmentCode = entity.GECompartmentCode,
         GESubCompartmentCode = entity.GESubCompartmentCode,
         GEPlotCode = entity.GEPlotCode,
         GEParcelCode = entity.GEParcelCode,
         ICForestPlotHistoryVillage = entity.ICForestPlotVillage,
         ICForestPlotHistoryArea = entity.ICForestPlotArea,
         ICForestTypeCode = entity.ICForestTypeCode,
         ICForestOrgCode = entity.ICForestOrgCode,
         ICTreeSpecCode = entity.ICTreeSpecCode,
         ICForestPlotHistoryLocationLongitude = entity.ICForestPlotLocationLongitude,
         ICForestPlotHistoryLocationLatitude = entity.ICForestPlotLocationLatitude,
         ICForestPlotHistoryPlantingYear = entity.ICForestPlotPlantingYear,
         ICForestPlotHistoryAvgYearCanopy = entity.ICForestPlotAvgYearCanopy,
         ICForestPlotHistoryVolumnPerHa = entity.ICForestPlotVolumnPerHa,
         ICForestPlotHistoryVolumnPerPlot = entity.ICForestPlotVolumnPerPlot,
         APActorCode = entity.APActorCode,
         FK_APActorID = entity.FK_APActorID,
         ICLandUseCertCode = entity.ICLandUseCertCode,
         ICConflictSitCode = entity.ICConflictSitCode,
         ICForestPlotHistoryLandUseTerune = entity.ICForestPlotLandUseTerune,
         FK_GECommuneID = entity.FK_GECommuneID,
         FK_GECompartmentID = entity.FK_GECompartmentID,
         FK_GEDistrictID = entity.FK_GEDistrictID,
         FK_GEStateProvinceID = entity.FK_GEStateProvinceID,
         FK_GESubCompartmentID = entity.FK_GESubCompartmentID,
         FK_ICForestOrgID = entity.FK_ICForestOrgID,
         FK_ICTreeSpecID = entity.FK_ICTreeSpecID,
         FK_ICLandUseCertID = entity.FK_ICLandUseCertID,
         FK_ICForestCertID = entity.FK_ICForestCertID,
         ICForestPlotHistoryReliability = entity.ICForestPlotReliability,
         FK_GEForestProtectionDepartmentID = entity.FK_GEForestProtectionDepartmentID,
         FK_GEPeoplesCommitteeID = entity.FK_GEPeoplesCommitteeID,
         ICForestPlotHistoryLatestReviewDate = entity.ICForestPlotLatestReviewDate,
         ICForestPlotHistoryFormisUUID = entity.ICForestPlotFormisUUID,
         ICForestPlotHistoryPlantingDate = entity.ICForestPlotPlantingDate,
         ICForestPlotHistoryCreatedDate = Clock.Now,
         FK_ADuserID = session.UserId,
         FK_ICForestPlotID = entity.Id,
     });
 }
Пример #6
0
 public static ForestPlotDto ToForestPlotDto(this ICForestPlot entity)
 {
     return(entity == null
         ? null
         : new ForestPlotDto
     {
         Area = entity.ICForestPlotArea,
         VolumnPerPlot = entity.ICForestPlotVolumnPerPlot,
         Commune = entity.GECommunes.ToDictionaryItemDto(),
         District = entity.GEDistrict.ToDictionaryItemDto(),
         StateProvince = entity.GEStateProvince.ToDictionaryItemDto(),
         TreeSpec = entity.ICTreeSpec.ToTreeSpecDto(),
         Compartment = entity.GECompartment.ToDictionaryItemDto(),
         SubCompartment = entity.GESubCompartment.ToDictionaryItemDto(),
         PlotCode = entity.GEPlotCode,
         Id = entity.Id
     });
 }
Пример #7
0
 public static ShortActorDto ToShortActorDto(this ICForestPlot entity)
 {
     return entity == null
         ? null
         : new ShortActorDto
         {
             Name = entity.APActor.APActorName,
             Type = entity.APActor?.APActorType.ToActorTypeDto(),
             Email = entity.APActor.APActorEmail,
             Phone = entity.APActor.APActorPhone,
             Website = entity.APActor.APActorWebsite,
             ForestPlot = entity.ToForestPlotDto(),
             AverageRating = entity.APActorReviews.Where(o => o.FK_APActorID == entity.FK_APActorID).Count() > 0 
             ? entity.APActorReviews.ToAverageRating(entity) : 5,
             ReviewCount = entity.APActorReviews.Where(o => o.FK_APActorID == entity.FK_APActorID).Count() > 0 
             ? entity.APActorReviews.Where(o => o.FK_APActorID == entity.FK_APActorID).Count() : 0
         };
 }
Пример #8
0
        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;
        }
Пример #9
0
        public async Task <UpdateTreeSpecForestPlotReportDto> UpdateTreeSpecForestPlotsAsync()
        {
            var deleteforestPlots = await _unitOfWork.GetRepository <ICForestPlot>()
                                    .GetAll()
                                    .SearchByFields("+", x => x.ICTreeSpecCode)
                                    .MakeQueryToDatabaseAsync();

            var forestPlots = deleteforestPlots
                              .GroupBy(
                x => new
            {
                x.ICTreeSpecCode,
                x.FK_GECommuneID,
                x.FK_GESubCompartmentID,
                x.GEPlotCode,
                x.ICForestPlotArea,
                x.ICForestPlotVolumnPerHa,
                x.ICForestPlotVolumnPerPlot
            })
                              .Select(x => x.First())
                              .ToArray();

            var newforestPlots = forestPlots.SelectMany(
                x => x.ICTreeSpecCode.SplitBy("+")
                .ConvertArray(
                    y =>
            {
                ICForestPlot forestPlot = new ICForestPlot();

                x.CopyTo(forestPlot);
                forestPlot.ICTreeSpecCode = y;

                return(forestPlot);
            }))
                                 .ToArray();

            using (var transaction = _unitOfWork.Context.Database.BeginTransaction())
            {
                _unitOfWork.Context.BulkDelete(deleteforestPlots);

                _unitOfWork.Context.BulkInsert(newforestPlots);

                transaction.Commit();
            }

            //await _unitOfWork.GetRepository<ICForestPlot>().DeleteAsync(x => forestPlots.Any(y => y.Id == x.Id));

            //foreach (var forestPlot in forestPlots)
            //{
            //    await _unitOfWork.GetRepository<ICForestPlot>().DeleteAsync(forestPlot);
            //}

            //await _unitOfWork.GetRepository<ICForestPlot>().BulkInsertAsync(newforestPlots);

            //await _unitOfWork.CompleteAsync();

            return(new UpdateTreeSpecForestPlotReportDto
            {
                ForestPlotCombineTreeSpecCodeCount = deleteforestPlots.Length,
                InsertedForestPlotCount = newforestPlots.Length,
            });
        }