예제 #1
0
        public Framework.Common.Service.Message.ResponseDto DeAssignUser(Common.DTO.UserDto user, int roleId)
        {
            ResponseDto   response = new ResponseDto();
            RoleBussiness roleBs   = new RoleBussiness();
            var           dbuser   = GetSingle(it => it.UserId == user.UserId);

            if (dbuser != null)
            {
                var dbRole = roleBs.GetSingle(it => it.RoleId == roleId);
                if (dbRole != null)
                {
                    UserToRoleTDataAccess userToRoleDa = new UserToRoleTDataAccess();
                    var relation = userToRoleDa.GetSingle(it => it.RoleId == roleId && it.UserId == user.UserId);
                    if (relation != null)
                    {
                        userToRoleDa.Delete(relation);
                    }
                    else
                    {
                        response.Response.AddBusinessException("رابطه نشده است!", BusinessExceptionEnum.Operational);
                    }
                }
                else
                {
                    response.Response.AddBusinessException("نقش موجود نیست", BusinessExceptionEnum.Operational);
                }
            }
            else
            {
                response.Response.AddBusinessException("کاربر موجود نیست", BusinessExceptionEnum.Operational);
            }
            return(response);
        }
예제 #2
0
        public Common.DTOContainer.RoleDtoContainer AssignedRoles(Common.DTO.UserDto user)
        {
            RoleDtoContainer container = new RoleDtoContainer();
            RoleBussiness    roleBs    = new RoleBussiness();
            var dbuser = GetSingle(it => it.UserId == user.UserId);

            if (dbuser != null)
            {
                UserToRoleTDataAccess userToRoleDa = new UserToRoleTDataAccess();
                var roleIds = userToRoleDa.GetAll(it => it.UserId == dbuser.UserId).Select(it => it.RoleId).ToList();
                foreach (var roleId in roleIds)
                {
                    var role = roleBs.GetSingle(it => it.RoleId == roleId);
                    container.RoleDtoList.Add(role);
                }
            }
            else
            {
                container.Response.AddBusinessException("کاربر موجود نیست", BusinessExceptionEnum.Operational);
            }
            return(container);
        }