public ActionResult Create(Document document, FormCollection form) { if (ModelState.IsValid) { db.Documents.Add(document); db.SaveChanges(); return RedirectToAction("Index"); } return View(document); }
public ActionResult Edit(Document document) { if (ModelState.IsValid) { db.Entry(document).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(document); }
public ActionResult Upload(FormCollection form) { string fileSavePath = ""; string uploadDir = "/Documents/"; var uploadedFile = Request.Files[0]; string fileName = Path.GetFileName(uploadedFile.FileName); fileSavePath = Server.MapPath(uploadDir + fileName); uploadedFile.SaveAs(fileSavePath); Document document = new Document(); document.Modified = document.Created = DateTime.Now; document.URI = uploadDir + fileName; if (!String.IsNullOrWhiteSpace(form["issueId"])) { Issue issue = db.Issues.Find(int.Parse(form["issueId"])); document.Issue = issue; db.Documents.Add(document); db.SaveChanges(); return RedirectToAction("Details", "Issue", new { id = issue.Id }); } if (!String.IsNullOrWhiteSpace(form["companyId"])) { Company company = db.Companies.Find(int.Parse(form["companyId"])); document.Company = company; db.Documents.Add(document); db.SaveChanges(); return RedirectToAction("Details", "Company", new { id = company.Id }); } return RedirectToAction("Index"); }