public async Task <IActionResult> EditWorkArea(WorkAreaEditViewModel model, IFormFile pic) { var workarea = _workAreaService.GetById(model.Id); if (ModelState.IsValid) { if (pic != null) { var extension = Path.GetExtension(pic.FileName); var picName = _categoryService.GetById(model.CategoryId).Url + extension; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/workarea-cover/" + picName); using var stream = new FileStream(path, FileMode.Create); await pic.CopyToAsync(stream); model.Picture = picName; workarea.Picture = model.Picture; } workarea.Desciption = model.Description.Replace(" ", " "); workarea.CategoryId = model.CategoryId; _workAreaService.Update(workarea); return(RedirectToAction("Index", "WorkArea", new { area = "Admin" })); } return(View()); }
public async Task <ActionResult> Update([FromBody] AreaRequest request) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(await _workAreaService.Update(request))); } catch (Exception ex) { return(BadRequest()); } }