public ActionResult NewUpload(string id, bool expirationdate = false, int referenceId = 0, int documentId = 0)
        {
            ViewBag.ExpirationDate = expirationdate;

            var document = new DocumentViewModel(id, referenceId);
            if (documentId != 0)
            {
                var dc = BO.Document.Instance.GetDocumentById(documentId);
                document.DocumentExtension = dc.DocumentExtension;

                document.IsRemoved = dc.IsRemoved;
                document.Id = documentId;
                document.LastUpdated = dc.LastUpdated;
                document.CreatedBy = dc.CreatedBy;
                document.UpdatedBy = dc.UpdatedBy;
                document.CreatedDate = dc.CreatedDate;
                document.ExpirationDate = dc.ExpirationDate;
                document.Name = dc.Name;
                document.Path = dc.Path;
                document.DocumentExtension = dc.Path;
                document.DocumentType = dc.DocumentType;

            }
            document.Path = "";
            document.Name = "";
            return View("Form", document);
        }
        public ActionResult Save(DocumentViewModel model, HttpPostedFileBase FileUpload)
        {
            var response = new ResponseObject();

            byte[] bytes;
            if (FileUpload.ContentLength > 0)
            {
                bytes = FileUpload.InputStream.ReadAllBinary();
            }
            else
            {
                bytes = null;
            }

            var rlModel = new Model.Models._Document.Document();
            rlModel.FileStream = bytes;
            rlModel.IsRemoved = model.IsRemoved;
            rlModel.Id = model.Id;
            rlModel.LastUpdated = model.LastUpdated;
            rlModel.CreatedBy = model.CreatedBy;
            rlModel.UpdatedBy = model.UpdatedBy;
            rlModel.CreatedDate = model.CreatedDate;
            rlModel.ExpirationDate = model.ExpirationDate;
            rlModel.Name = FileUpload.FileName;
            rlModel.Path = "form";
            rlModel.DocumentExtension = FileUpload.FileName.Split('.').Last();
            rlModel.DocumentType = FileUpload.ContentType;

            if (model.ReferenceId != null)
                response = BO.Document.Instance.SaveDocument(rlModel, model.Reference, model.ReferenceId.Value);
            else
            {
                response.Status = false;
                response.Messages.Add("Dados incorretos.");
            }

            return Json(response);
        }