public async Task <JsonResult> SaveAndUpdate(CustomerMediaImageDto input)
        {
            CustomerMediaImageDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                var profilePictureFile = Request.Form.Files.First();
                Logger.Info("开始上传文件");
                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                Logger.Info("文件大小:" + fileBytes.Length);
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                var    extra    = fileInfo.Extension.Substring(fileInfo.Extension.IndexOf(".") + 1);
                string fileUrl  = await _fileServer.UploadFile(fileBytes, extra, MpMessageType.image.ToString());

                input.FilePathOrUrl = fileUrl;
                var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
                input.MediaID = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.image);
            }

            if (input.Id == 0)
            {
                result = await _CustomerMediaImageAppService.Create(input);
            }
            else
            {
                result = await _CustomerMediaImageAppService.Update(input);
            }
            return(Json(result));
        }
Esempio n. 2
0
 public CreateOrEditCustomerMediaImageViewModel(CustomerMediaImageDto output)
 {
     output.MapTo(this);
 }