Skip to content

Instantly share code, notes, and snippets.

@CodeWizardGenius
Last active September 8, 2022 14:17
Show Gist options
  • Save CodeWizardGenius/69d03fce2ee97493382be5a3274c8ada to your computer and use it in GitHub Desktop.
Save CodeWizardGenius/69d03fce2ee97493382be5a3274c8ada to your computer and use it in GitHub Desktop.
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