Example #1
0
        public void SaveUserGroupMap(int userID)
        {
            UserGroup_Mapping usermap = new UserGroup_Mapping();

            usermap.UserGroupID = 1;
            usermap.UserID      = userID;
            usermap.IsActive    = true;
            usermap.CreatedOn   = DateTime.Now;
            _userGroupMap.Insert(usermap);
        }
Example #2
0
        public bool AddUserList(UserGroupModel model)
        {
            using (var scope = new TransactionScope())
            {
                var userGroups = _userGroupMap.GetWithInclude(x => x.UserGroupID == model.UserGroupID).ToList();
                if (model.UserCheckList.Count == 0)
                {
                    userGroups.ForEach(x =>
                    {
                        _userGroupMap.Delete(Convert.ToInt32(x.Id));
                    });
                    scope.Complete();
                    return(true);
                }


                var userGroupList = userGroups.Select(x => x.UserID.Value).ToList();
                var addedList     = model.UserCheckList.Except(userGroupList).ToList();
                var deleteList    = userGroupList.Except(model.UserCheckList).ToList();
                var usergroupMap  = userGroups.Where(x => deleteList.Contains(x.UserID.Value)).Select(x => x.Id).ToList();
                usergroupMap.ForEach(x =>
                {
                    _userGroupMap.Delete(Convert.ToInt32(x));
                });

                addedList.ForEach(x =>
                {
                    UserGroup_Mapping usermap = new UserGroup_Mapping();
                    usermap.UserGroupID       = model.UserGroupID;
                    usermap.UserID            = x;
                    usermap.IsActive          = true;
                    usermap.CreatedOn         = DateTime.Now;
                    _userGroupMap.Insert(usermap);
                });
                scope.Complete();
            }
            return(true);
        }