예제 #1
0
        public async virtual Task <ActionResult> CreateDoc(string subject, CancellationToken cancellationToken)
        {
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToFailureAction(MVC.NewsFeed.Default(CurrentUser.LanguageCode), Resource.Error));
            }

            if (!IsGoogleAuthenticated)
            {
                return(Json(false));
            }

            try
            {
                if (string.IsNullOrEmpty(subject))
                {
                    subject = Resource.NoName;
                }
                var file = GoogleAuthUtils.Create(GoogleService, subject.LimitLength(100));
                return(Json(new { Content = RenderPartialViewToString(MVC.Shared.Views.Attachment, new UrlViewModel()
                    {
                        Url = file.AlternateLink, Title = file.Title, IconUrl = CustomAppSettings.GoogleDocIconUrl
                    }) }));
            }
            catch (GoogleApiException e)
            {
                if (e.HttpStatusCode == HttpStatusCode.Unauthorized)
                {
                    return(Json(new { error = "Unauthorized" }));
                }

                return(Json(new { error = e.Message }));
            }
        }
예제 #2
0
        public virtual ActionResult SelectDocs(List <UrlViewModel> docs)
        {
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToFailureAction(MVC.NewsFeed.Default(CurrentUser.LanguageCode), Resource.Error));
            }

            if (!IsGoogleAuthenticated)
            {
                return(Json(false));
            }

            foreach (var doc in docs)
            {
                GoogleAuthUtils.UpdatePermissions(GoogleService, doc.Id);
            }

            string result = string.Empty;

            foreach (var doc in docs)
            {
                result += RenderPartialViewToString(MVC.Shared.Views.Attachment, doc);
            }

            return(Json(new { Content = result }));
        }