public IActionResult Edit(CampusEditViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } else { string uniqueFileName = null; if (viewModel.Photos != null && viewModel.Photos.Count > 0) { foreach (IFormFile photo in viewModel.Photos) { var extension = Path.GetExtension(photo.FileName).ToLower(); if (extension == ".jpg" || extension == ".jpeg" || extension == ".png") { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); photo.CopyTo(new FileStream(filePath, FileMode.Create)); } else { throw new Exception("Dosya türü .JPG , .JPEG veya .PNG olmalıdır.."); } } } Campus editedCampus = new Campus() { Id = viewModel.Id, Name = viewModel.Name, Description = viewModel.Description, EditorContent = viewModel.EditorContent, ImageUrl = uniqueFileName, StatusId = viewModel.StatusId, Address = viewModel.Address, Telephone = viewModel.Telephone, EmailAddress = viewModel.EmailAddress, Fax = viewModel.Fax, EditDate = DateTime.Now, EditorMemberId = 1 }; _campusService.Edit(editedCampus); return(RedirectToAction("Index")); } }