public ActionResult UpdateDocumentLibrary(Models.DocumentsViewModel input)
        {
            try
            {
                if ((input != null) && (input.EditSPDocumentLibrary != null) && (TryValidateModel(input)) && (ModelState.IsValid))
                {
                    var docLib = input.EditSPDocumentLibrary;

                    // Update document library settings to db
                    docLib.DocumentLibraryId = Repository.DocumentLibrary.Save(docLib);

                    // Return successful response
                    return(Json(new
                    {
                        Success = true,
                        DocumentLibraryId = docLib.DocumentLibraryId
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Success = false,
                    message = "An internal error occurred - please try again.  If this error persists, please contact your system administrator",
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                Success = false,
                message = "Doc lib was not saved - enter required values.",
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> SaveDocumentLibrary(Models.DocumentsViewModel input)
        {
            try
            {
                if ((input != null) && (input.NewSPDocumentLibrary != null) && (TryValidateModel(input)) && (ModelState.IsValid))
                {
                    var docLib = input.NewSPDocumentLibrary;

                    // Save document library to db
                    docLib.DocumentLibraryId = Repository.DocumentLibrary.Save(docLib);

                    // Copy all documents from document library to Azure storage.. this may take a while if the files are large or there are many files...
                    SharePoint      sp        = new SharePoint();
                    List <Document> documents = await sp.DownloadFilesToAzure(docLib);

                    // Save documents that were downloaded from SharePoint and saved to Azure Blob Storage to SQL db
                    if (documents != null)
                    {
                        foreach (Document d in documents)
                        {
                            long docId = Repository.Documents.Save(d);
                        }
                    }
                    // Return successful response
                    return(Json(new
                    {
                        Success = true,
                        DocumentLibraryId = docLib.DocumentLibraryId
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Success = false,
                    message = "An internal error occurred - please try again.  If this error persists, please contact your system administrator",
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                Success = false,
                message = "Doc lib was not saved - enter required values.",
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Documents(bool?documentUploadSucceeded, string failedMsg)
        {
            var vm = new Models.DocumentsViewModel();

            vm.Documents               = Repository.Documents.GetAll();
            vm.SPDocumentLibraries     = Repository.DocumentLibrary.GetAll();
            vm.Audiences               = Repository.Audience.GetAll();
            vm.DocumentUploadSucceeded = documentUploadSucceeded;
            vm.DocumentUploadFailedMsg = failedMsg;
            var    svm         = new Models.DocumentSettingsViewModel();
            string _moduleName = Repository.Documents.ModuleName;

            svm.ConnectionString = Repository.ConfigurationItemRepository.GetUniqueItem(_moduleName, "ConnectionString");
            svm.AccountName      = Repository.ConfigurationItemRepository.GetUniqueItem(_moduleName, "AccountName");
            svm.AccessKey        = Repository.ConfigurationItemRepository.GetUniqueItem(_moduleName, "AccessKey");
            vm.Settings          = svm;
            return(View(vm));
        }
        public ActionResult UpdateDocument(Models.DocumentsViewModel input)
        {
            try
            {
                if ((input != null) && (input.EditDocument != null) && input.EditDocument.Name != null && input.EditDocument.DocumentId != 0)
                {
                    var editDocument    = input.EditDocument;
                    var currentDocument = Repository.Documents.Get(editDocument.DocumentId);

                    // copy other settings that are not editable
                    editDocument.DocumentLibraryId = currentDocument.DocumentLibraryId;
                    editDocument.Uploaded          = currentDocument.Uploaded;
                    editDocument.Url       = currentDocument.Url;
                    editDocument.Extension = currentDocument.Extension;

                    // Update document library settings to db
                    var id = Repository.Documents.Save(editDocument);

                    // Return successful response
                    return(Json(new
                    {
                        Success = true,
                        DocumentId = editDocument.DocumentId
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Success = false,
                    message = "An internal error occurred - please try again.  If this error persists, please contact your system administrator",
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                Success = false,
                message = "Document was not saved - enter required values.",
            }, JsonRequestBehavior.AllowGet));
        }