Exemplo n.º 1
0
 private static string GetCurrentLocation()
 {
     return(QfsUtility.FormatLocation(SpManager.GetSpHost()));
 }
Exemplo n.º 2
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));
                }
            }
        }