Esempio n. 1
0
        public ActionResult <Treat> Update([FromRoute] string id, [FromBody] Treat treat)
        {
            var admin = _treatService.Get(id);

            if (admin == null)
            {
                return(NotFound());
            }

            _treatService.Update(id, treat);

            return(treat);
        }
        public async Task <IActionResult> EditTreat(Treat treat)
        {
            if (!ModelState.IsValid)
            {
                return(View(treat));
            }
            await _treatService.Update(treat);

            //上传文件
            var files = Request.Form.Files;

            foreach (var file in files)
            {
                //转换成二进制
                Byte[] fileData = new Byte[(int)file.Length];
                using (var memoryStream = new MemoryStream())
                {
                    await file.CopyToAsync(memoryStream);

                    fileData = memoryStream.ToArray();
                }

                //保存图片到服务器
                var r = await _lovePlatformApi.UploadImage(
                    new UploadImageInput { AvatarBuffer = fileData, Folder = "cure-record" });

                var fileName = r.ResultValue;

                _treatImageService.Add(new TreatImage()
                {
                    ImagePath = fileName, TreatId = treat.Id, UserId = treat.UserId
                });
            }

            return(RedirectToAction("Detail", "User", new { id = treat.UserId }));
        }
 public async Task <OutputBase> Update([FromBody] Treat treat)
 {
     return(await _treatService.Update(treat));
 }