Example #1
0
        public GroupDto GetGroupById(int groupId)
        {
            var group    = _groupDataProvider.GetGroupById(groupId);
            var groupDto = Mapper.Map <Group, GroupDto>(group);

            groupDto.Users       = group.UserGroups?.Select(ug => Mapper.Map <User, UserDto>(ug.User)).ToList() ?? new List <UserDto>();
            groupDto.Permissions = group.GroupPermissions?.Select(gp => Mapper.Map <Permission, PermissionDto>(gp.Permission)).ToList() ?? new List <PermissionDto>();

            return(groupDto);
        }
Example #2
0
        public UserDto GetUserByEmailAndPassword(string email, string password, bool includeGroups)
        {
            var user = _userDataProvider.GetUserByEmailAndPassword(email, password);

            if (user == null)
            {
                return(null);
            }

            List <GroupDto> groupDtos = null;

            if (includeGroups && user.UserGroups != null)
            {
                var groups = user.UserGroups.Select(ug => _groupDataProvider.GetGroupById(ug.GroupId)).ToList();
                groupDtos = groups.Select(Mapper.Map <Group, GroupDto>).ToList();
            }

            var userDto = Mapper.Map <User, UserDto>(user);

            userDto.Groups = groupDtos;

            return(userDto);
        }