//
 // 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");
        }
        //
        // 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);
        }