public ActionResult Edit(int id = 0)
        {
            var document = db.Documents.Find(id);
            PurposeEditViewModel model = new PurposeEditViewModel();

            model.id            = id;
            model.document_text = document.documentText;
            model.docType       = document.DocumentType.name;

            return(View(model));
        }
        public ActionResult Edit(PurposeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var document = db.Documents.Find(model.id);
                document.updateDate      = DateTime.Now;
                document.documentText    = model.document_text;
                db.Entry(document).State = EntityState.Modified;
                if (model.isNewVersion)
                {
                    var hist_document = new HistDocument(document);
                    hist_document.changeReason = model.changeReason;
                    document.version++;
                    db.HistDocuments.Add(hist_document);
                    db.Entry(document).State = EntityState.Modified;
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }