コード例 #1
0
ファイル: GroupsController.cs プロジェクト: khoainv/Framework
 // GET: Admin/Groups/Edit/5
 public async Task<ActionResult> Edit(string id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Group group = await GroupManager.FindByIdAsync(id);
     if (group == null)
     {
         return HttpNotFound();
     }
     var model = new GroupViewModel(group);
     model = await AttachEditAsync(model, null);
     return View(model);
 }
コード例 #2
0
ファイル: GroupsController.cs プロジェクト: khoainv/Framework
        public async Task<ActionResult> Edit([Bind(Include = "Id,Name,Description,ParentId")] Group group
            ,params string[] SelectedPermision)
        {
            Group oldgrp = await GroupManager.FindByIdAsync(group.Id);
            if (oldgrp == null)
            {
                return HttpNotFound();
            }
            if(oldgrp.Name == UGConstants.GroupAdmin && group.Name!=UGConstants.GroupAdmin)
            {
                ModelState.AddModelError("Name","Không được sửa tên của Group Admin");
            }
            if (oldgrp.Name == UGConstants.GroupAnonymous && group.Name != UGConstants.GroupAnonymous)
            {
                ModelState.AddModelError("Name", "Không được sửa tên của Group Anonymous");
            }
            if (ModelState.IsValid)
            {
                GroupManager.Detach(oldgrp);
                var result = await GroupManager.UpdateAsync(group);
                if (result.Succeeded)
                {
                    var perInGrp = PermissionManager.FindPermissionsByOnlyGroupId(group.Id).Select(x => x.Id);
                    SelectedPermision = SelectedPermision ?? new string[] { };
                    result = await GroupManager.AddPermissionToGroupsAsync(group.Id, SelectedPermision.Except(perInGrp).ToArray<string>());
                    if (result.Succeeded)
                    {
                        result = await GroupManager.RemovePermissionFromGroupsAsync(group.Id, perInGrp.Except(SelectedPermision).ToArray<string>());
                        if (result.Succeeded)
                        {
                            WorkContextBase.ClearCache();
                            return RedirectToAction("Index");
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", result.Errors.First());
                }

            }
            var model = new GroupViewModel(group);
            model = await AttachEditAsync(model, SelectedPermision);
            return View(model);
        }
コード例 #3
0
ファイル: GroupsController.cs プロジェクト: khoainv/Framework
        private async Task<GroupViewModel> AttachEditAsync(GroupViewModel model, string[] SelectedPermision)
        {
            var grpSelected = await PermissionManager.FindPermissionsByOnlyGroupId(model.Id).Select(x => x.Id).ToListAsync();

            if (SelectedPermision != null)
                grpSelected = SelectedPermision.ToList();
            model.AllPermissionsInGroupList = await PermissionManager.FindPermissionsByGroupId(model.Id).ToListAsync();
            model.PermissionsList = await PermissionManager.Permissions
                .Select(x => new PermissionViewModel() { Permission = x, Selected = grpSelected.Contains(x.Id) })
                .ToListAsync();
            model.AllUsersInGroupList = await GroupManager.FindUserGroupById(model.Id).ToListAsync();
            return model;
        }