public ActionResult Create(FormCollection collection) { try { //TODO: Don't know if it is worth the risk, but would be better // to check if the person signed on actually owns the document int documentId = int.Parse(collection["DocumentId"]); string categories = collection["Categories"]; List<string> categoryList = new List<string>(); foreach(string category in categories.Split(',')) { categoryList.Add(category.Trim()); } using (var db = new DocumentDataContext()) { List<Category> categoriesPresent = db.getCategoriesForDocument(documentId); foreach (Category c in categoriesPresent) { categoryList.RemoveAll(delegate(string catName) { return catName == c.Name; }); } db.addCategoriesToDocument(categoryList, documentId); } return RedirectToAction("Edit", "Document", new { id = documentId}); } catch { return View(); } }
// // GET: /Document/Details/5 public ActionResult Details(int id) { DocumentViewModel model = new DocumentViewModel(); using (var db = new DocumentDataContext()) { DataLoadOptions options = new DataLoadOptions(); options.LoadWith<Document>(d => d.User); options.LoadWith<Document>(d => d.Comments); options.LoadWith<Comment>(d => d.User); options.LoadWith<Document>(d => d.CategoryDocuments); options.LoadWith<CategoryDocument>(d => d.Category); db.LoadOptions = options; model.CurrentDocument = db.getDocument(id); } return View(model); }
public ActionResult Edit(int id) { DocumentViewModel model = new DocumentViewModel(); using (var db = new DocumentDataContext()) { DataLoadOptions options = new DataLoadOptions(); options.LoadWith<Document>(d => d.User); db.LoadOptions = options; model.CurrentDocument = db.getDocument(id); } //If the User tries to get smart with the query string if (model.CurrentDocument.User.UserName == User.Identity.Name) return View(model); else return RedirectToAction("Index"); }
public ActionResult Create(FormCollection collection) { try { using (var db = new DocumentDataContext()) { Comment comment = new Comment { DocumentId = int.Parse(collection["DocumentId"]), CreatedAt = DateTime.Now, Description = collection["Description"], UserId = db.getUserIdForUserName(User.Identity.Name) }; db.insertComment(comment); } return RedirectToAction("Details", "Document", new { id = collection["DocumentId"]}); } catch { return View(); } }
public ActionResult Create(FormCollection collection) { try { using (var db = new DocumentDataContext()) { Document document = new Document { Title = collection["Title"].ToString(), Description = collection["Description"].ToString(), CreatedAt = DateTime.Now, UserId = db.getUserIdForUserName(User.Identity.Name) }; db.Documents.InsertOnSubmit(document); db.SubmitChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(FormCollection collection) { try { using (var db = new DocumentDataContext()) { if (Request.Files.Count == 1 && Request.Files[0].ContentLength < 102400000) { string internalFileName = new StringBuilder(12).AppendRandomString(12).ToString(); while (System.IO.File.Exists(Server.MapPath(Url.DocumentFileUrl(internalFileName)))) { internalFileName = new StringBuilder(12).AppendRandomString(12).ToString(); } Request.Files[0].SaveAs(Server.MapPath(Url.DocumentFileUrl(internalFileName))); } } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, FormCollection collection) { try { using (var db = new DocumentDataContext()) { Document doc = db.getDocument(id); //Check to see if the user who made the post was the user who created the document if (doc.User.UserName != User.Identity.Name) return RedirectToAction("Index"); doc.Title = collection["Title"]; doc.Description = collection["Description"]; db.updateDocument(doc); } return RedirectToAction("Index"); } catch { return View(); } }
// // GET: /Document/ public ActionResult Index() { DocumentViewModel model = new DocumentViewModel(); using (var db = new DocumentDataContext()) { DataLoadOptions options = new DataLoadOptions(); options.LoadWith<Document>(u => u.User); db.LoadOptions = options; model.Documents = db.getAllDocuments(); } return View(model); }