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> SaveHrefs(IEnumerable <HrefAssociation> newHrefs, IEnumerable <HrefAssociation> updateHrefs)
        {
            try
            {
                using (var context = SpManager.GetSharePointContext(HttpContext))
                {
                    if (!SpManager.IsUserAdmin(context))
                    {
                        return(AccessDenied());
                    }

                    var userKey = GetUserKey();

                    await SQLTemplateStorageManager.SaveNewHrefAssociations(userKey, newHrefs ?? Enumerable.Empty <HrefAssociation>());

                    await SQLTemplateStorageManager.UpdateHrefAssociations(userKey, updateHrefs ?? Enumerable.Empty <HrefAssociation>());
                }
            }
            catch (Exception e)
            {
                return(Json(e.StackTrace));
            }

            return(Json(new { success = true }));
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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 #5
0
        public ActionResult UploadTemplate(string formName, bool update = false)
        {
            using (var context = SpManager.GetSharePointContext(HttpContext))
            {
                if (!SpManager.IsUserAdmin(context))
                {
                    return(AccessDenied());
                }

                return(View(new UploadTemplateViewModel
                {
                    CreateNew = !update,
                    FormName = formName
                }));
            }
        }
Beispiel #6
0
        public async Task <ActionResult> DeleteTemplate(string templateName)
        {
            using (var context = SpManager.GetSharePointContext(HttpContext))
            {
                if (!SpManager.IsUserAdmin(context))
                {
                    return(Json(false));
                }
            }

            if (String.IsNullOrWhiteSpace(templateName))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var result = await TemplateManager.DeleteTemplate(templateName, StorageContext);

            return(Json(result));
        }
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));
                }
            }
        }