示例#1
0
        public async Task <string> NewFarmInfoAsync(NewFarmInfoCmd cmd, string currentMemberId)
        {
            var timeNow      = DateTime.Now;
            var extension    = cmd.MainImg.Name.Split('.').LastOrDefault();
            var fileName     = ObjectId.NewId();
            var fileFullName = fileName + "." + extension;
            var path         = Path.Combine(GetUploadDirectory(), fileFullName);

            using (FileStream destinationStream = File.Create(path))
            {
                await cmd.MainImg.Value.CopyToAsync(destinationStream).ConfigureAwait(false);
            }

            using (var conn = CreateConnection())
            {
                var farmInfo = new FarmInfo
                {
                    Name         = cmd.Name,
                    Longitude    = cmd.Longitude,
                    Latitude     = cmd.Latitude,
                    Description  = cmd.Description,
                    MainImg      = fileName,
                    Extension    = extension,
                    Remark       = cmd.Remark,
                    Address      = cmd.Address,
                    Telephone    = cmd.Telephone,
                    Type         = cmd.Type,
                    PersonLiable = cmd.PersonLiable,
                    Status       = cmd.Status,
                    CreatedBy    = currentMemberId,
                    ModifiedBy   = currentMemberId,
                    CreatedOn    = timeNow,
                    ModifiedOn   = timeNow
                };
                await conn.InsertAsync <FarmInfo>(farmInfo).ConfigureAwait(false);

                return(farmInfo.Id);
            };
        }
示例#2
0
 public async Task <string> CheckNewFarmInfoCmdValidatableAsync(NewFarmInfoCmd cmd)
 {
     if (cmd.Name.IsNullOrWhiteSpace())
     {
         return("农场名称必填");
     }
     if (await _farmService.ExistFarmInfoByNameAsync(cmd.Name).ConfigureAwait(false))
     {
         return("农场名称已存在");
     }
     if (cmd.Telephone.IsNullOrWhiteSpace())
     {
         return("农场电话必填");
     }
     if (await _farmService.ExistFarmInfoByTelephoneAsync(cmd.Telephone).ConfigureAwait(false))
     {
         return("农场电话已存在");
     }
     if (cmd.Address.IsNullOrWhiteSpace())
     {
         return("农场地址必填");
     }
     return(null);
 }