public static ShrimpCrop ToShrimpCrop(this ShrimpCropDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            ShrimpCrop entity = new ShrimpCrop();

            entity.CopyPropertiesFrom(dto);

            return(entity);
        }
        public static ShrimpCrop ToShrimpCrop(this UpdateShrimpCropDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            ShrimpCrop entity = new ShrimpCrop();

            entity.CopyPropertiesFrom(dto);
            entity.FromDate          = dto.FromDate.FromUnixTimeStamp();
            entity.ToDate            = dto.ToDate.FromUnixTimeStamp();
            entity.FarmingLocationId = dto.FarmingLocation.Id;
            entity.ShrimpBreedId     = dto.ShrimpBreed.Id;

            return(entity);
        }
        public static ShrimpCropResultDto ToShrimpCropResultDto(this ShrimpCrop entity)
        {
            if (entity == null)
            {
                return(null);
            }

            ShrimpCropResultDto dto = new ShrimpCropResultDto();

            dto.CopyPropertiesFrom(entity);

            dto.FarmingLocation = entity.FarmingLocation.ToShortFarmingLocationDto();
            dto.ShrimpBreed     = entity.ShrimpBreed.ToShrimpBreedDto();
            dto.FromDate        = entity.FromDate.ToSecondsTimestamp();
            dto.ToDate          = entity.ToDate.ToSecondsTimestamp();
            dto.Factors         = entity.ShrimpCropManagementFactors == null ? null : entity.ShrimpCropManagementFactors.OrderBy(x => x.CreatedAt).Select(x => x.ToShrimpCropManagementFactorDto()).ToArray();

            return(dto);
        }
        public static ShrimpCropDto ToShrimpCropDto(this ShrimpCrop entity)
        {
            if (entity == null)
            {
                return(null);
            }

            ShrimpCropDto dto = new ShrimpCropDto();

            dto.CopyPropertiesFrom(entity);

            dto.ShrimpBreed         = entity.ShrimpBreed.ToShrimpBreedDto();
            dto.FarmingLocation     = entity.FarmingLocation.ToShortFarmingLocationDto();
            dto.FromDate            = entity.FromDate.ToSecondsTimestamp();
            dto.ToDate              = entity.ToDate.ToSecondsTimestamp();
            dto.HasManagementFactor = entity.ShrimpCropManagementFactors.Count > 0;

            return(dto);
        }
Пример #5
0
        public async Task <ShrimpCropResultDto> CreateShrimpCrop(CreateShrimpCropDto dto)
        {
            _logger.LogInformation("Start method create shrimp crop");

            ValidateShrimpCrop(dto);

            ShrimpCrop shrimpCrop = dto.ToShrimpCrop();

            shrimpCrop.Code = await GenerateShrimpCropCode();

            shrimpCrop.CreatedBy = _sessionService.UserId;

            await this.DatabaseConnectService.Connection.InsertAsync(shrimpCrop);

            _redisCache.Remove(CacheConst.AllShrimpCrop);

            _logger.LogInformation("end method create shrimp crop");


            return(await GetShrimpCropById(shrimpCrop.Id));
        }