コード例 #1
0
        public async Task <ActionResult> EntryEdit_Partial(EditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }
            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                BlogEntry data = await dataProvider.GetItemAsync(model.Identity);

                if (data == null)
                {
                    throw new Error(this.__ResStr("notFound", "Blog entry with id {0} not found"), model.Identity);
                }
                // save updated item
                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display

                UpdateStatusEnum status = await dataProvider.UpdateItemAsync(data);

                if (status != UpdateStatusEnum.OK)
                {
                    throw new Error(this.__ResStr("errSaving", "An unexpected error occurred saving the blog entry - {0}", status));
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Blog entry saved")));
            }
        }
コード例 #2
0
        public async Task <ActionResult> SearchEdit_Partial(EditModel model)
        {
            using (SearchDataProvider dataProvider = new SearchDataProvider()) {
                SearchData data = await dataProvider.GetItemWithUrlAsync(model.SearchDataId);

                if (data == null)
                {
                    throw new Error(this.__ResStr("alreadyDeleted", "The search keyword with id {0} has been removed and can no longer be updated.", model.SearchDataId));
                }

                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display

                switch (await dataProvider.UpdateItemAsync(data))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The search keyword with id {0} has been removed and can no longer be updated.", model.SearchDataId));

                case UpdateStatusEnum.NewKeyExists:
                    throw new Error(this.__ResStr("alreadyExists", "A search keyword with id {0} already exists.", model.SearchDataId));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Search keyword saved"), OnClose: OnCloseEnum.Return, OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
コード例 #3
0
        public async Task <ActionResult> RolesEdit_Partial(EditModel model)
        {
            using (RoleDefinitionDataProvider dataProvider = new RoleDefinitionDataProvider()) {
                string         originalRole = model.OriginalName;
                RoleDefinition role         = await dataProvider.GetItemAsync(originalRole);// get the original item

                if (role == null)
                {
                    throw new Error(this.__ResStr("alreadyDeleted", "The role named \"{0}\" has been removed and can no longer be updated.", originalRole));
                }

                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                role = model.GetData(role); // merge new data into original
                model.SetData(role);        // and all the data back into model for final display

                switch (await dataProvider.UpdateItemAsync(originalRole, role))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The role named \"{0}\" has been removed and can no longer be updated.", originalRole));

                case UpdateStatusEnum.NewKeyExists:
                    ModelState.AddModelError(nameof(model.Name), this.__ResStr("alreadyExists", "A role named \"{0}\" already exists.", model.Name));
                    return(PartialView(model));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Role \"{0}\" saved", role.Name), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
コード例 #4
0
        public async Task <ActionResult> UnifiedSetEdit_Partial(EditModel model)
        {
            using (UnifiedSetDataProvider unifiedSetDP = new UnifiedSetDataProvider()) {
                UnifiedSetData unifiedSet = await unifiedSetDP.GetItemAsync(model.UnifiedSetGuid);// get the original item

                if (unifiedSet == null)
                {
                    throw new Error(this.__ResStr("alreadyDeleted", "The unified page set with id {0} has been removed and can no longer be updated", model.UnifiedSetGuid));
                }

                ObjectSupport.CopyData(unifiedSet, model, ReadOnly: true); // update read only properties in model in case there is an error
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                unifiedSet = model.GetData(unifiedSet); // merge new data into original
                model.SetData(unifiedSet);              // and all the data back into model for final display

                switch (await unifiedSetDP.UpdateItemAsync(unifiedSet))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The unified page set with id {0} has been removed and can no longer be updated", model.UnifiedSetGuid));

                case UpdateStatusEnum.NewKeyExists:
                    ModelState.AddModelError(nameof(model.Name), this.__ResStr("alreadyExists", "An unified page set named \"{0}\" already exists", model.Name));
                    return(PartialView(model));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Unified page set saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
コード例 #5
0
ファイル: PageEdit.cs プロジェクト: moayyaed/YetaWF-Modules
        public async Task <ActionResult> PageEdit_Partial(EditModel model)
        {
            PageDefinition page = await PageDefinition.LoadAsync(model.PageGuid);

            if (page == null)
            {
                throw new Error(this.__ResStr("alreadyDeleted", "This page has been removed and can no longer be updated."));
            }

            model.UpdateData(page);
            ObjectSupport.CopyData(page, model.Page, ReadOnly: true); // update read only properties in model in case there is an error
            model.Page.FavIcon_Data = page.FavIcon_Data;              // copy favicon
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }
            page = model.GetData(page);  // merge new data into original
            model.SetData(page);         // and all the data back into model for final display

            await page.SaveAsync();      // this handles changing the Url automatically

            MenuList.ClearCachedMenus(); // page changes may affect all menus so clear the menu cache (this only clears current session)
            // if we're in a popup and the parent page is the page we're editing, then force a reload

            //$$$$ rename with querystring doesn't work
            OnPopupCloseEnum popupClose = OnPopupCloseEnum.ReloadModule;

            if (PageDefinition.IsSamePage(Manager.QueryReturnToUrl.Url, model.Page.Url))
            {
                popupClose = OnPopupCloseEnum.ReloadParentPage;
            }
            return(FormProcessed(model, this.__ResStr("okSaved", "Page settings saved"), OnPopupClose: popupClose));
        }
コード例 #6
0
        public async Task <ActionResult> CommentEdit_Partial(EditModel model)
        {
            await model.UpdateDataAsync();

            using (BlogCommentDataProvider dataProvider = new BlogCommentDataProvider(model.EntryIdentity)) {
                BlogComment data = await dataProvider.GetItemAsync(model.Identity);

                if (data == null)
                {
                    throw new Error(this.__ResStr("alreadyDeleted", "The comment entry with id {0} has been removed and can no longer be updated", model.Identity));
                }
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                // save updated item
                data = model.GetData(data); // merge new data into original
                await model.SetData(data);  // and all the data back into model for final display

                switch (await dataProvider.UpdateItemAsync(data))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The comment entry with id {0} has been removed and can no longer be updated", model.Identity));

                case UpdateStatusEnum.NewKeyExists:
                    throw new Error(this.__ResStr("alreadyExists", "A comment with id {0} already exists.", model.Identity));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Comment saved")));
            }
        }
コード例 #7
0
        public ActionResult LocalizeEditFile_Partial(EditModel model, bool RestoreDefaults = false)
        {
            Package          package = Package.GetPackageFromPackageName(model.PackageName);
            LocalizationData data    = null;

            if (RestoreDefaults)
            {
                data = Localization.Load(package, model.TypeName, Localization.Location.DefaultResources);

                Localization.SaveAsync(package, model.TypeName, Localization.Location.InstalledResources, null); // delete it
                Localization.SaveAsync(package, model.TypeName, Localization.Location.CustomResources, null);    // delete it

                ModelState.Clear();
                EditModel newModel = new EditModel {
                    PackageName           = model.PackageName,
                    TypeName              = model.TypeName,
                    Custom                = model.ForceCustom || model.Custom,
                    CustomRO              = model.ForceCustom || model.Custom,
                    CurrentLanguage       = MultiString.ActiveLanguage,
                    HiddenCurrentLanguage = MultiString.ActiveLanguage,
                    ForceCustom           = model.ForceCustom,
                };
                newModel.SetData(data); // and all the data back into model for final display
                return(FormProcessed(newModel, this.__ResStr("okReset", "Localization resource default restored - The localization file has been removed - If you click Save or Apply, a new custom/installed addon file will be created. To keep the defaults only, simply close this form"), OnClose: OnCloseEnum.UpdateInPlace, OnPopupClose: OnPopupCloseEnum.UpdateInPlace));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }
                data = Localization.Load(package, model.TypeName, Localization.Location.CustomResources);
                if (data == null)
                {
                    data = Localization.Load(package, model.TypeName, Localization.Location.InstalledResources);
                }
                if (data == null)
                {
                    data = Localization.Load(package, model.TypeName, Localization.Location.DefaultResources);
                }
                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display

                model.Custom          = model.ForceCustom || model.Custom;
                model.CustomRO        = model.ForceCustom || model.Custom;
                model.CurrentLanguage = model.HiddenCurrentLanguage;

                if (model.Custom)
                {
                    Localization.SaveAsync(package, model.TypeName, Localization.Location.CustomResources, data);
                }
                else
                {
                    Localization.SaveAsync(package, model.TypeName, Localization.Location.InstalledResources, data);
                }

                return(FormProcessed(model, this.__ResStr("okSaved", "Localization resource saved"), OnPopupClose: OnPopupCloseEnum.ReloadNothing));
            }
        }
コード例 #8
0
        public async Task <ActionResult> ProfileEdit_Partial(EditModel model)
        {
            using (UserInfoDataProvider userInfoDP = new UserInfoDataProvider()) {
                Manager.NeedUser();

                bool     newUser  = false;
                UserInfo userInfo = await userInfoDP.GetItemAsync(model.UserId);

                if (userInfo == null)
                {
                    newUser  = true;
                    userInfo = new UserInfo();
                }
                model.UpdateData(userInfo);

                // in case of apply, we're just updating the form with new fields - we chose a postback when switching
                // the country as potentially many different address formats could be supported which could overwhelm client side processing
                // so we only provide the fields for one country to the form.
                if (IsApply)
                {
                    ModelState.Clear();
                    return(PartialView(model));
                }
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                userInfo = model.GetData(userInfo); // merge new data into original
                model.SetData(userInfo);            // and all the data back into model for final display

                if (newUser)
                {
                    await userInfoDP.AddItemAsync(userInfo);
                }
                else
                {
                    await userInfoDP.UpdateItemAsync(userInfo);
                }

                string msg = Module.SaveMessage;
                if (string.IsNullOrWhiteSpace(msg))
                {
                    msg = this.__ResStr("okSaved", "Profile saved");
                }
                if (string.IsNullOrWhiteSpace(Module.PostSaveUrl))
                {
                    return(FormProcessed(model, msg));
                }
                else
                {
                    return(FormProcessed(model, msg, OnClose: OnCloseEnum.GotoNewPage, NextPage: Module.PostSaveUrl));
                }
            }
        }
コード例 #9
0
        public async Task <ActionResult> MinimalSettingsEdit_Partial(EditModel model)
        {
            using (UserDataProvider dataProvider = new UserDataProvider()) {
                UserData data = await dataProvider.GetItemAsync();

                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }
                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display
                await dataProvider.UpdateItemAsync(data);

                return(FormProcessed(model, this.__ResStr("okSaved", "Your settings have been successfully saved"), ForceRedirect: true));
            }
        }
コード例 #10
0
        public async Task <ActionResult> EditExtension_Partial(EditModel model)
        {
            string originalExtension = model.OriginalExtension;

            using (ExtensionEntryDataProvider dataProvider = new ExtensionEntryDataProvider()) {
                ExtensionEntry data = await dataProvider.GetItemAsync(originalExtension);// get the original item

                if (data == null)
                {
                    ModelState.AddModelError("Extension", this.__ResStr("alreadyDeleted", "Extension {0} has been removed and can no longer be updated", originalExtension));
                    return(PartialView(model));
                }
                ObjectSupport.CopyData(data, model, ReadOnly: true); // update read only properties in model in case there is an error
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display

                switch (await dataProvider.UpdateItemAsync(data))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    ModelState.AddModelError("Name", this.__ResStr("alreadyDeleted", "Extension {0} has been removed and can no longer be updated", model.OriginalExtension));
                    return(PartialView(model));

                case UpdateStatusEnum.NewKeyExists:
                    ModelState.AddModelError("Name", this.__ResStr("alreadyExists", "Extension {0} already exists.", data.Extension));
                    return(PartialView(model));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Extension saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
コード例 #11
0
        public async Task <ActionResult> CategoryEdit_Partial(EditModel model)
        {
            int originalCategory = model.Identity;

            using (BlogCategoryDataProvider dataProvider = new BlogCategoryDataProvider()) {
                // get the original item
                BlogCategory data = await dataProvider.GetItemAsync(originalCategory);

                if (data == null)
                {
                    throw new Error(this.__ResStr("alreadyDeletedId", "The blog category with id {0} has been removed and can no longer be updated.", originalCategory));
                }

                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                // save updated item
                data = model.GetData(data); // merge new data into original
                model.SetData(data);        // and all the data back into model for final display

                switch (await dataProvider.UpdateItemAsync(data))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The blog category named \"{0}\" has been removed and can no longer be updated.", model.Category.ToString()));

                case UpdateStatusEnum.NewKeyExists:
                    ModelState.AddModelError(nameof(model.Category), this.__ResStr("alreadyExists", "A blog category named \"{0}\" already exists.", model.Category.ToString()));
                    return(PartialView(model));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Blog category saved"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
コード例 #12
0
ファイル: UsersEdit.cs プロジェクト: moayyaed/YetaWF-Modules
        public async Task <ActionResult> UsersEdit_Partial(EditModel model)
        {
            using (UserDefinitionDataProvider dataProvider = new UserDefinitionDataProvider()) {
                string         originalUserName = model.OriginalUserName;
                UserDefinition user             = await dataProvider.GetItemAsync(originalUserName);

                if (user == null)
                {
                    throw new Error(this.__ResStr("alreadyDeleted", "The user named \"{0}\" has been removed and can no longer be updated.", originalUserName));
                }
                if (!ModelState.IsValid)
                {
                    return(PartialView(model));
                }

                LoginConfigData config = await LoginConfigDataProvider.GetConfigAsync();

                switch (config.RegistrationType)
                {
                case RegistrationTypeEnum.NameAndEmail: {
                    List <DataProviderFilterInfo> filters = DataProviderFilterInfo.Join(null, new DataProviderFilterInfo {
                            Field = nameof(UserDefinition.Email), Operator = "==", Value = model.Email,
                        });
                    UserDefinition userExists = await dataProvider.GetItemAsync(filters);

                    if (userExists != null && user.UserName != userExists.UserName)
                    {
                        ModelState.AddModelError(nameof(model.Email), this.__ResStr("emailUsed", "An account using email address {0} already exists.", model.Email));
                        return(PartialView(model));
                    }
                    break;
                }

                case RegistrationTypeEnum.EmailOnly:
                    model.UserName = model.Email;
                    break;

                case RegistrationTypeEnum.NameOnly:
                    model.Email = model.UserName;
                    break;
                }

                user = model.GetData(user); // merge new data into original
                model.SetData(user);        // and all the data back into model for final display

                switch (await dataProvider.UpdateItemAsync(originalUserName, user))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The user named \"{0}\" has been removed and can no longer be updated.", originalUserName));

                case UpdateStatusEnum.NewKeyExists:
                    ModelState.AddModelError(nameof(model.UserName), this.__ResStr("alreadyExists", "A user named \"{0}\" already exists.", model.UserName));
                    return(PartialView(model));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "User updated"), OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }