Beispiel #1
0
        public async Task <ActionResult> ManageHrefs()
        {
            try
            {
                using (var context = SpManager.GetSharePointContext(HttpContext))
                {
                    if (!SpManager.IsUserAdmin(context))
                    {
                        return(AccessDenied());
                    }

                    var userKey   = GetUserKey();
                    var templates = await GetTemplatesAsync(userKey);

                    var hrefs = (await SQLTemplateStorageManager.ListHrefAssociations(userKey)).ToList();

                    return(View(new ManageHrefsModel
                    {
                        Hrefs = hrefs,
                        Templates = templates
                    }));
                }
            }
            catch (Exception e)
            {
                throw QfsUtility.HandleException(e);
            }
        }
Beispiel #2
0
        public async Task <ActionResult> ManageTemplates()
        {
            try
            {
                var checkUsageCountData = await CheckIsUsageExceededAsync();

                var location             = checkUsageCountData.Item1;
                var monthlyFormOpenCount = checkUsageCountData.Item2;
                var isUsageExceeded      = checkUsageCountData.Item3;

                using (var context = SpManager.GetSharePointContext(HttpContext))
                {
                    if (!SpManager.IsUserAdmin(context))
                    {
                        return(AccessDenied());
                    }

                    var templates = await GetTemplatesAsync();

                    return(View(new ManageTemplatesViewModel
                    {
                        Templates = templates,
                        MonthlyFormOpenCount = monthlyFormOpenCount,
                        Location = location,
                        IsUsageExceeded = isUsageExceeded
                    }));
                }
            }
            catch (Exception e)
            {
                throw QfsUtility.HandleException(e);
            }
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            try
            {
                if (filterContext == null)
                {
                    throw new ArgumentNullException("filterContext");
                }

                Uri redirectUrl;
                switch (SharePointContextProvider.CheckRedirectionStatus(filterContext.HttpContext, out redirectUrl))
                {
                case RedirectionStatus.Ok:
                    return;

                case RedirectionStatus.ShouldRedirect:
                    filterContext.Result = new RedirectResult(redirectUrl.AbsoluteUri);
                    break;

                case RedirectionStatus.CanNotRedirect:
                    filterContext.Result = new ViewResult {
                        ViewName = "Error"
                    };
                    break;
                }
            }
            catch (Exception e)
            {
                throw QfsUtility.HandleException(e);
            }
        }
Beispiel #4
0
        public ActionResult Index()
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(System.Web.HttpContext.Current);

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
            }
            return(View(new IndexViewModel
            {
                Version = QfsUtility.InternalGetQFSVersion()
            }));
        }
Beispiel #5
0
        public async Task <ActionResult> Index()
        {
            var isUsageExceeded = (await CheckIsUsageExceededAsync()).Item3;

            using (var context = SpManager.GetSharePointContext(HttpContext))
            {
                return(View(new IndexViewModel
                {
                    IsAdmin = SpManager.IsUserAdmin(context),
                    Version = QfsUtility.InternalGetQFSVersion(),
                    IsUsageExceeded = isUsageExceeded
                }));
            }
        }
Beispiel #6
0
 private static string GetCurrentLocation()
 {
     return(QfsUtility.FormatLocation(SpManager.GetSpHost()));
 }
Beispiel #7
0
        public async Task <ActionResult> UploadTemplate(string formName, string location, bool update = false, bool allowDowngrade = false)
        {
            using (var context = SpManager.GetSharePointContext(HttpContext))
            {
                if (!SpManager.IsUserAdmin(context))
                {
                    return(AccessDenied());
                }

                if (!string.IsNullOrWhiteSpace(formName) && Request.Files.Count > 0)
                {
                    location = QfsUtility.FormatLocation(location);

                    if (!update && string.IsNullOrWhiteSpace(location))
                    {
                        return(Json(new UploadTemplateViewModel
                        {
                            CreateNew = true,
                            FormName = formName,
                            Message = "Cannot add template, location is missing"
                        }));
                    }

                    try
                    {
                        var template = Request.Files[0];
                        var realm    = GetUserKey();

                        context.Load(context.Web);
                        context.ExecuteQuery();

                        context.Load(context.Web.CurrentUser);
                        context.ExecuteQuery();
                        var currentUser = context.Web.CurrentUser.Title;

                        var tuple = await SQLTemplateStorageManager.StoreTemplate(realm, formName, !update, template.InputStream,
                                                                                  template.FileName, allowDowngrade, StorageContext, currentUser, location);

                        return(Json(new UploadTemplateViewModel
                        {
                            HideContent = true,
                            Message = UploadedMessage(update),
                            IsUploaded = tuple.Item1,
                            OldVersion = tuple.Item2,
                            NewVersion = tuple.Item3
                        }));
                    }
                    catch (Exception e)
                    {
                        return(Json(new UploadTemplateViewModel
                        {
                            CreateNew = !update,
                            FormName = formName,
                            Message = e.Message
#if DEBUG
                            ,
                            Stack = e.StackTrace
#endif
                        }));
                    }
                }
                else
                {
                    return(UploadTemplate(formName, update));
                }
            }
        }