public ActionResult Index(string folderPath)
        {
            // Check for existence of api keys
            var siteSettings = _orchard.WorkContext.CurrentSite.As <DropboxSettingsPart>();

            if (string.IsNullOrEmpty(siteSettings.ApiKey) || string.IsNullOrEmpty(siteSettings.ApiSecret))
            {
                return(View("Index_SetupApi"));
            }

            var userSettings = _orchard.WorkContext.CurrentUser.As <DropboxUserSettingsPart>();

            if (string.IsNullOrEmpty(userSettings.UserToken) || string.IsNullOrEmpty(userSettings.UserSecret))
            {
                return(RedirectToAction("Authorise", "DropboxAuthentication",
                                        new {
                    redirectUrl = Url.Action("Index", new { folderPath })
                }));
            }

            try {
                var client   = _dropbox.GetClient(_orchard.WorkContext.CurrentUser);
                var contents = client.GetMetaData("").Contents.ToClientViewModel();
                return(View(new DropboxStorageViewModel {
                    FolderPath = folderPath,
                    Contents = contents
                }));
            }
            catch (DropboxException dbe) {
                Logger.Error(dbe, "{0}, {1}", dbe.StatusCode, dbe.Response.ErrorMessage);
                return(View("Index_SetupApi"));
            }
        }
 public ActionResult Authorise(string redirectUrl)
 {
     try {
         var client = _dropbox.GetClient();
         if (client == null)
         {
             throw new DropboxException();
         }
         var url = client.GetTokenAndBuildUrl(string.Format("{0}/Kobowi.Dropbox/DropboxAuthentication/AuthCallback",
                                                            _orchard.WorkContext.CurrentSite.BaseUrl));
         _httpContext.Current().Session["DropnetUserLogin"] = client.UserLogin;
         return(View(new DropboxAuthoriseViewModel {
             AuthoriseUrl = url,
             RedirectUrl = redirectUrl
         }));
     } catch (DropboxException dbe) {
         Logger.Error(dbe, "Authorise");
         return(View("Index_SetupApi"));
     }
 }