示例#1
0
 //This method is required by Google Drive API
 public ActionResult IndexAsync(CancellationToken cancellationToken)
 {
     AuthorizationCodeWebApp.AuthResult authorization = GoogleDriveAPIHelper.getAuthorization(this);
     if (authorization.Credential == null)
     {
         return(new RedirectResult(authorization.RedirectUri));
     }
     else
     {
         return(RedirectToAction(nameof(Index)));
     }
 }
示例#2
0
        public ActionResult Create(string submitButton, Guid?ParentId, HttpPostedFileBase File, Guid?FileId, string FileDescription, bool?IsGlobalFile, Guid?DirectoryId, string DirectoryName, bool?IsGlobalDirectory)
        {
            FilesModel model = new FilesModel();

            if (ParentId == null)
            {
                model.ParentId = RootId;
            }
            else
            {
                model.ParentId = (Guid)ParentId;
            }

            if (IsGlobalFile == true || IsGlobalDirectory == true)
            {
                model.Branches_Id = null;
            }
            else
            {
                model.Branches_Id = Helper.getActiveBranchId(Session);
            }

            if (submitButton == BUTTONVALUE_UPLOADFILE || submitButton == BUTTONVALUE_UPLOADREVISION)
            {
                if (File == null || File.ContentLength == 0)
                {
                    UtilWebMVC.setBootboxMessage(this, "Invalid File");
                }
                else
                {
                    AuthorizationCodeWebApp.AuthResult authorization = GoogleDriveAPIHelper.getAuthorization(this);
                    if (authorization.Credential == null)
                    {
                        UtilWebMVC.setBootboxMessage(this, "Google Login was required. Please navigate to the folder and try to upload the file again.");
                        return(RedirectToAction(nameof(IndexAsync)));
                    }
                    else
                    {
                        authorization = GoogleDriveAPIHelper.checkExpiration(this, authorization);

                        string OnlineFileId = GoogleDriveAPIHelper.UploadToDrive(GoogleDriveAPIHelper.GetServiceForWebApplication(authorization), File);
                        if (GoogleDriveAPIHelper.isFileUploadSuccessful(this, OnlineFileId))
                        {
                            model.Filename     = File.FileName;
                            model.OnlineFileId = OnlineFileId;
                            model.Notes        = FileDescription;

                            if (submitButton == BUTTONVALUE_UPLOADFILE)
                            {
                                add(model);
                            }
                            else
                            {
                                FilesModel originalModel = get((Guid)FileId);
                                model.ParentId = originalModel.ParentId;
                                add(model);
                                originalModel.ParentId = model.Id;
                                update(originalModel);
                            }
                        }
                    }
                }
            }
            else if (submitButton == BUTTONVALUE_CREATEDIRECTORY || submitButton == BUTTONVALUE_UPDATEDIRECTORY)
            {
                if (string.IsNullOrWhiteSpace(DirectoryName))
                {
                    UtilWebMVC.setBootboxMessage(this, "Invalid Name");
                }
                else
                {
                    model.DirectoryName = DirectoryName;
                    if (submitButton == BUTTONVALUE_CREATEDIRECTORY)
                    {
                        add(model);
                    }
                    else
                    {
                        model.Id = (Guid)DirectoryId;
                        update(model);
                    }
                }
            }

            return(null);
        }