public ActionResult Edit(PaperMain paper) { if(ModelState.IsValid) { paper.Creater = User.Identity.Name; db.Entry(paper).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction("UploadFile", new { title = paper.Title}); } return View(paper); }
public ActionResult Create(PaperMain paper) { var errors = ModelState.SelectMany(m => m.Value.Errors); if (ModelState.IsValid) { bool result = db.Papers.Any(m => m.Title == paper.Title); if (!result) { db.Papers.Add(paper); db.SaveChanges(); return RedirectToAction("UploadFile", new { title = paper.Title}); } else ModelState.AddModelError("", "This Paper Already Exists"); } return View(); }
public ActionResult UploadFile(HttpPostedFileBase upfile,PaperMain pp) { if(upfile!=null) { if(upfile.ContentLength >0) { //String ss = "~/UploadFile/" + User.Identity.Name + "/"; String ss = Server.MapPath("~/Upload/" + User.Identity.Name + "/"); if (!Directory.Exists(ss)) Directory.CreateDirectory(ss); String saveName = Path.Combine(Server.MapPath("~/Upload/" + User.Identity.Name + "/"), pp.Title + ".txt"); upfile.SaveAs(saveName); var result = from m in db.Papers where m.Title == pp.Title select m; foreach (PaperMain rr in result) { rr.PDF = Server.MapPath("~/Upload/" + User.Identity.Name + "/") + pp.Title + ".txt"; db.Entry(rr).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); } } return RedirectToAction("Index"); }