public async Task <IActionResult> Create([Bind("Name,PasswordNo,ImageUrl")] EditAnimalModel model, IFormFile image) { if (!ModelState.IsValid) { return(View(model)); } var result = await _animalService.AddAsync(model); if (!result.Succeeded) { ModelState.AddModelError("Error", result.Error); return(View(model)); } if (image != null) { var imgUrl = Path.Combine("/Images" + "/Animals/" + result.Data.Id + Path.GetExtension(image.FileName)); var ok = FileHelper.SaveImageFromStream(image.OpenReadStream(), Path.GetFullPath(_environment.WebRootPath + imgUrl)); if (ok) { model = result.Data; model.ImageUrl = imgUrl; await _animalService.EditAsync(model); } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit([FromBody] UpdateAnimalRequest request) { await _animalService.EditAsync(request, User); return(Ok()); }