public ActionResult Edit(InfoBlockModel infoBlock, HttpPostedFileBase imageFile) { InfoBlockModel dbInfoBlock = db.InfoBlocks.Find(infoBlock.InfoBlockId); if (ModelState.IsValid) { infoBlock.EntryCreated = dbInfoBlock.EntryCreated; if (infoBlock.ImageToDelete == false) { infoBlock.Image = Utils.FileManager.UpdateFile(dbInfoBlock.Image, imageFile, "Projects", dbInfoBlock.Project.Guid); } else { infoBlock.Image = Utils.FileManager.DeleteFile(dbInfoBlock.Image); infoBlock.ImageToDelete = false; } db.Entry(dbInfoBlock).State = EntityState.Detached; db.Entry(infoBlock).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } else { return View(dbInfoBlock); } }
public ActionResult Create(int id, InfoBlockModel infoBlock, HttpPostedFileBase imageFile) { if (ModelState.IsValid) { infoBlock.ProjectId = id; infoBlock.EntryCreated = DateTime.Now; infoBlock.Image = Utils.FileManager.UploadFile(imageFile, "Projects", infoBlock.Project.Guid); db.Entry(infoBlock).State = EntityState.Added; db.SaveChanges(); return RedirectToAction("Index"); } else { return View(); } }