コード例 #1
0
        public async Task <ActionResult> AddUserToModule(string data, string fieldPrefix, string newUser, Guid editGuid)
        {
            // validate
            if (string.IsNullOrWhiteSpace(newUser))
            {
                throw new Error(this.__ResStr("noParm", "No user name specified"));
            }
            int userId = await Resource.ResourceAccess.GetUserIdAsync(newUser);

            if (userId == 0)
            {
                throw new Error(this.__ResStr("noUser", "User {0} doesn't exist.", newUser));
            }
            string userName = await Resource.ResourceAccess.GetUserNameAsync(userId);

            // check duplicate
            List <ModuleDefinition.GridAllowedUser> list = Utility.JsonDeserialize <List <ModuleDefinition.GridAllowedUser> >(data);

            if ((from l in list where l.UserId == userId select l).FirstOrDefault() != null)
            {
                throw new Error(this.__ResStr("dupUser", "User {0} has already been added", newUser));
            }

            // render
            ModuleDefinition.GridAllowedUser entry = new ModuleDefinition.GridAllowedUser {
                DisplayUserId   = userId,
                UserId          = userId,
                View            = ModuleDefinition.AllowedEnum.Yes,
                DisplayUserName = userName
            };
            return(await GridRecordViewAsync(await AllowedUsersEditComponent.GridRecordAsync(fieldPrefix, entry, editGuid)));
        }
コード例 #2
0
        public async Task <string> RenderAsync(SerializableList <ModuleDefinition.AllowedUser> model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            bool header = PropData.GetAdditionalAttributeValue("Header", true);

            GridModel grid = new GridModel()
            {
                GridDef = GetGridModel(header)
            };

            grid.GridDef.ExtraData = new ExtraData {
                EditGuid = Manager.CurrentModuleEdited.ModuleGuid
            };
            grid.GridDef.DirectDataAsync = async(int skip, int take, List <DataProviderSortInfo> sorts, List <DataProviderFilterInfo> filters) => {
                List <ModuleDefinition.GridAllowedUser> list = new List <ModuleDefinition.GridAllowedUser>();
                if (model != null)
                {
                    foreach (ModuleDefinition.AllowedUser u in model)
                    {
                        ModuleDefinition.GridAllowedUser user = new ModuleDefinition.GridAllowedUser();
                        ObjectSupport.CopyData(u, user);
                        await user.SetUserAsync(u.UserId);

                        list.Add(user);
                    }
                }
                DataSourceResult data = new DataSourceResult {
                    Data  = list.ToList <object>(),
                    Total = list.Count,
                };
                return(data);
            };

            hb.Append($@"
<div class='yt_yetawf_moduleedit_allowedusers t_edit' id='{DivId}'>
    {await HtmlHelper.ForDisplayAsAsync(Container, PropertyName, FieldName, grid, nameof(grid.GridDef), grid.GridDef, "Grid", HtmlAttributes: HtmlAttributes)}");

            using (Manager.StartNestedComponent(FieldName)) {
                NewModel newModel = new NewModel();
                hb.Append($@"
    <div class='t_newvalue'>
        {await HtmlHelper.ForLabelAsync(newModel, nameof(newModel.NewValue))}
        {await HtmlHelper.ForEditAsync(newModel, nameof(newModel.NewValue))}
        <input name='btnAdd' type='button' value='Add' disabled='disabled' />
    </div>");
            }

            GridModel gridAll = new GridModel()
            {
                GridDef = GetGridAllUsersModel()
            };
            AllowedUsersSetup setup = new AllowedUsersSetup {
                AddUrl    = Utility.UrlFor(typeof(AllowedUsersController), nameof(AllowedUsersController.AddUserToModule)),
                GridId    = grid.GridDef.Id,
                GridAllId = gridAll.GridDef.Id
            };

            hb.Append($@"
    <div id='{DivId}_coll'>
        {await ModuleActionHelper.BuiltIn_ExpandAction(__ResStr("lblFindUsers", "Find Users"), __ResStr("ttFindUsers", "Expand to find user names available on this site")).RenderAsNormalLinkAsync() }
    </div>
    <div id='{DivId}_exp' style='display:none'>
        {await ModuleActionHelper.BuiltIn_CollapseAction(__ResStr("lblAllUserNames", "All User Names"), __ResStr("ttAllUserNames", "Shows all user names available on this site - Select a user name to update the text box above, so the user name can be added to the list of user names - Click to close")).RenderAsNormalLinkAsync() }
        {await HtmlHelper.ForDisplayAsAsync(Container, PropertyName, FieldName, gridAll, nameof(gridAll.GridDef), gridAll.GridDef, "Grid")}
    </div>
</div>");

            Manager.ScriptManager.AddLast($@"
$YetaWF.expandCollapseHandling('{DivId}', '{DivId}_coll', '{DivId}_exp');
new YetaWF_ModuleEdit.AllowedUsersEditComponent('{DivId}', {Utility.JsonSerialize(setup)});");

            return(hb.ToString());
        }