Exemple #1
0
        public ActionResult CreateNewGroup(GroupModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return RedirectToAction("Error", "Base", new { eID = 0 });
                }

                var group = _repository.FindGroupByName(model.GroupName);
                if (group != null)
                {
                    return RedirectToAction("Error", "Base", new { eID = 1 });
                }

                var newGroup = new UserGroup
                                   {
                                       GroupName = model.GroupName,
                                       DisplayName = model.DisplayName,
                                       Level = model.Level,
                                       CreatedByUserID = int.Parse(User.Identity.Name),
                                       CreatedOnDate = DateTime.Now
                                   };

                _repository.AddNewGroup(newGroup);
                _repository.CommitChanges();
                return RedirectToAction("Index");
            }
            catch (Exception)
            {
                return RedirectToAction("Error", new {eID = 0});
            }
        }
Exemple #2
0
        public void AddNewGroup(UserGroup userGroup)
        {
            try
            {
                DB.AddToUserGroups(userGroup);
                List<Permission> permissionList = FindPermissionsByLevel(userGroup.Level.Value).ToList();
                var permissionGroupIDList = permissionList.Select(permission => permission.ID).ToList();

                foreach (var permissdionID in permissionGroupIDList)
                {
                    var permissiongroup = new Permissions_Group
                    {
                        GroupID = userGroup.ID,
                        PermissionID = permissdionID
                    };
                    AddNewPermissionGroup(permissiongroup);
                }
            }
            catch (Exception)
            {
                throw new Exception("Lỗi thêm nhóm người dùng");
            }
        }
Exemple #3
0
        public void UpdateGroup(UserGroup group)
        {
            try
            {
                var existingGroup = DB.UserGroups.First(g => g.ID == group.ID);
                existingGroup.GroupName = group.GroupName;
                existingGroup.DisplayName = group.DisplayName;
                existingGroup.Level = group.Level;
                existingGroup.LastModifiedOnDate = group.LastModifiedOnDate;
                existingGroup.LastModifiedByUserID = group.LastModifiedByUserID;

                // delete old permission
                var oldPermissionList = DB.Permissions_Groups.Where(p => p.GroupID == group.ID);
                if (oldPermissionList.Any())
                {
                    foreach (var permissionsGroup in oldPermissionList)
                    {
                        DeletePermissionGroup(permissionsGroup.ID);
                    }
                }

                // update new permission
                List<Permission> newpermissionList = FindPermissionsByLevel(group.Level.Value).ToList();
                var newpermissionGroupIDList = newpermissionList.Select(permission => permission.ID).ToList();

                foreach (var permissdionID in newpermissionGroupIDList)
                {
                    var permissiongroup = new Permissions_Group
                    {
                        GroupID = group.ID,
                        PermissionID = permissdionID
                    };
                    AddNewPermissionGroup(permissiongroup);
                }
            }
            catch (Exception)
            {
                throw new Exception("Lỗi cập nhật nhóm người dùng");
            }
        }
Exemple #4
0
 /// <summary>
 /// Create a new UserGroup object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="groupName">Initial value of the GroupName property.</param>
 public static UserGroup CreateUserGroup(global::System.Int32 id, global::System.String groupName)
 {
     UserGroup userGroup = new UserGroup();
     userGroup.ID = id;
     userGroup.GroupName = groupName;
     return userGroup;
 }
Exemple #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the UserGroups EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUserGroups(UserGroup userGroup)
 {
     base.AddObject("UserGroups", userGroup);
 }