Пример #1
0
 public ActionResult EditPage(string title)
 {
     Page temp = db.Pages.First(p => p.Title == title);
     EditViewModel model = new EditViewModel
     {
         Content = temp.Content,
         Title = temp.Title,
         PictureSource = temp.PictureSource,
         HasItems = temp.HasProducts
     };
     return View(model);
 }
Пример #2
0
 public ActionResult EditPage(EditViewModel model)
 {
     if (ModelState.IsValid)
     {
         var tempPage = db.Pages.First(p => p.Title == model.Title);
         if (model.Picture != null && tempPage.PictureSource != null)
         {
             string oldpath = Request.MapPath("~/Content/Photos/" + tempPage.PictureSource);
             if (System.IO.File.Exists(oldpath))
                 System.IO.File.Delete(oldpath);
         }
         string fileName = Guid.NewGuid().ToString();
         string filePath = fileName + Path.GetExtension(model.Picture.FileName);
         string path = Path.Combine(Server.MapPath(@"~/Content/Photos/"), filePath);
         model.Picture.SaveAs(path);
         tempPage.PictureSource = filePath;
         tempPage.Content = model.Content;
         tempPage.Title = model.Title;
         db.SaveChanges();
         return RedirectToAction("index");
     }
     return View();
 }