Beispiel #1
0
 public CreateOrEditCustomerServiceResponseTextViewModel(CustomerServiceResponseTextDto output)
 {
     output.MapTo(this);
 }
Beispiel #2
0
        public async Task <JsonResult> SaveAndUpdate(CustomerServiceResponseTextDto input)
        {
            CustomerServiceResponseTextDto result = null;

            input.LastModificationTime = DateTime.Now;
            if (Request.Form.Files.Count > 0)
            {
                IFormFile profilePictureFile = null;
                string    fileUrl            = null;
                if (input.ReponseContentType == (int)CustomerServiceMsgType.image)
                {
                    profilePictureFile = Request.Form.Files.First(m => m.Name == "UploadPic");
                }
                else if (input.ReponseContentType == (int)CustomerServiceMsgType.video)
                {
                    profilePictureFile = Request.Form.Files.First(m => m.Name == "UploadVideo");
                }
                else if (input.ReponseContentType == (int)CustomerServiceMsgType.voice)
                {
                    profilePictureFile = Request.Form.Files.First(m => m.Name == "UploadVoice");
                }

                if (profilePictureFile != null)
                {
                    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);
                    fileUrl = await _fileServer.UploadFile(fileBytes, extra, "CustomerCommon");

                    input.PreviewImgUrl = fileUrl;
                    var filename = fileUrl.Substring(fileUrl.LastIndexOf("/") + 1);
                }

                if (!string.IsNullOrWhiteSpace(fileUrl))
                {
                    if (input.ReponseContentType == (int)CustomerServiceMsgType.image)
                    {
                        input.MediaId = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.image);
                    }
                    else if (input.ReponseContentType == (int)CustomerServiceMsgType.video)
                    {
                        input.MediaId = await _wxMediaUpload.UploadAndGetMediaID(input.MpID, fileUrl, MpMessageType.voice);
                    }
                    else if (input.ReponseContentType == (int)CustomerServiceMsgType.voice)
                    {
                        input.MediaId = await _wxMediaUpload.UploadVideoAndGetMediaID(input.MpID, fileUrl, MpMessageType.video, input.Title, input.Description);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(input.MediaId))
                        {
                            input.MediaId = Guid.NewGuid().ToString();
                        }
                    }
                }
            }

            if (input.Id == 0)
            {
                result = await _CustomerServiceResponseTextAppService.Create(input);
            }
            else
            {
                result = await _CustomerServiceResponseTextAppService.Update(input);
            }
            return(Json(result));
        }