Last active
September 8, 2022 14:17
-
-
Save CodeWizardGenius/69d03fce2ee97493382be5a3274c8ada to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WriterValidator writerValidator = new WriterValidator(); | |
WriterManager writerManager = new WriterManager(new EfWriterDal()); | |
[HttpGet] | |
public ActionResult EditWriter(int id) | |
{ | |
var writerValue = writerManager.GetByID(id); | |
return View(writerValue); | |
} | |
[HttpPost] | |
public ActionResult EditWriter(Writer writer, int id) | |
{ | |
var writerValue = writerManager.GetByID(id); | |
string Yol; | |
if (writer.WriterImage == null) | |
{ | |
Yol = "~/img/Writer/user1.jpg"; | |
writer.WriterImage = Yol; | |
} | |
else | |
{ | |
Yol = "~/img/Writer/" + writer.WriterImage.ToString(); | |
} | |
ValidationResult result = writerValidator.Validate(writer); | |
if (Request.Files.Count != 0) | |
{ | |
string DosyaAdi = Path.GetFileName(Request.Files[0].FileName); | |
if (DosyaAdi!=null&&DosyaAdi.Length > 0) | |
{ | |
// string Uzanti = Path.GetExtension(Request.Files[0].FileName); | |
Yol = "~/img/Writer/" + DosyaAdi; | |
Request.Files[0].SaveAs(Server.MapPath(Yol)); | |
writer.WriterImage = Yol; | |
} | |
} | |
if (result.IsValid) | |
{ | |
writer.WriterImage = Yol; | |
writerManager.WriterUpdate(writer); | |
return RedirectToAction("Index"); | |
} | |
else | |
{ | |
foreach (var item in result.Errors) | |
{ | |
ModelState.AddModelError(item.PropertyName, item.ErrorMessage); | |
} | |
} | |
return View(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment