private void ValidateShrimpCrop(CreateShrimpCropDto dto) { if (dto.Name.IsNullOrWhiteSpace() || dto.FarmingLocation == null || dto.ShrimpBreed == null || dto.FromDate > dto.ToDate) { throw new BusinessException("Invalid parameter!", ErrorCode.INVALID_PARAMETER); } }
public async Task <BaseResponse <ShrimpCropResultDto> > Create([FromBody] CreateShrimpCropDto dto) { if (dto == null) { throw new BusinessException("Invalid parameter!", ErrorCode.INVALID_PARAMETER); } var response = new BaseResponse <ShrimpCropResultDto> { Data = await _shrimpCropService.CreateShrimpCrop(dto), Status = true }; return(await Task.FromResult(response)); }
public static ShrimpCrop ToShrimpCrop(this CreateShrimpCropDto dto) { if (dto == null) { return(null); } ShrimpCrop entity = new ShrimpCrop(); entity.CopyPropertiesFrom(dto); entity.Id = Guid.NewGuid(); entity.FromDate = dto.FromDate.FromUnixTimeStamp(); entity.ToDate = dto.ToDate.FromUnixTimeStamp(); entity.CreatedAt = DateTime.UtcNow; entity.FarmingLocationId = dto.FarmingLocation.Id; entity.ShrimpBreedId = dto.ShrimpBreed.Id; return(entity); }
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)); }