public async Task <IActionResult> Edit(SahibindenBitirmeProjesi.Entity.Entities.Concrete.Models model) { if (ModelState.IsValid) { if (model.ImageUpload != null) { string uploadDir = Path.Combine(_webHostEnvironment.WebRootPath, "media/models"); if (!string.Equals(model.Image, "noimage.png")) { string oldPath = Path.Combine(uploadDir, model.Image); if (System.IO.File.Exists(oldPath)) { System.IO.File.Delete(oldPath); } } string imageName = Guid.NewGuid().ToString() + "_" + model.ImageUpload.FileName; string filePath = Path.Combine(uploadDir, imageName); FileStream fileStream = new FileStream(filePath, FileMode.Create); await model.ImageUpload.CopyToAsync(fileStream); fileStream.Close(); model.Image = imageName; } await _modelsRepository.Update(model); TempData["Success"] = "Model başarıyla güncellendi..!"; return(RedirectToAction("List")); } else { TempData["Error"] = "Model güncellenemedi..!"; return(View(model)); } }
public async Task <IActionResult> Update(int id, [FromBody] ModelItemRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _modelsRepository.Update(id, request); return(NoContent()); } catch (InvalidBrandException) { string errorText = String.Format("Brand with ID: {0} doesn't exist", request.BrandId); return(StatusCode(StatusCodes.Status409Conflict, new { Message = errorText })); } catch (InvalidModelException) { return(NotFound()); } }