Пример #1
0
        public Group_ExpertsViewModel(Guid groupId, Guid?userId)
        {
            SelfExpertTags = new List <TagViewModel>();
            ExpertsList    = new List <Group_Experts_ExpertViewModel>();

            var group = GroupService.GetGroupByLabelOrId(groupId);

            GroupUrl = group.Url;

            if (userId.HasValue)
            {
                var uig = GroupService.UserInGroup(userId.Value, group);

                if (uig != null)
                {
                    IsMember = true;

                    if (uig.Expert != null)
                    {
                        IsExpert       = true;
                        SelfExpertTags = uig.Expert.Tags.Select(x => new TagViewModel(x)).ToList();
                    }
                }
            }

            var currenUserId = Guid.Empty;

            if (UserContext.Current != null)
            {
                currenUserId = UserContext.Current.Id;
            }

            //TODO: дописать нормальный join, пока эксперты выводяться хаотично
            var experts = (from expert in DataService.PerThread.ExpertSet
                           join groupMember in DataService.PerThread.GroupMemberSet
                           on expert.GroupMember.Id equals groupMember.Id
                           where groupMember.GroupId == groupId && groupMember.UserId != currenUserId
                           select new { expert.Id, groupMember.User }).ToList();

            //join vote in DataService.PerRequest.ExpertVoteSet
            //on mergeExpert.Id equals vote.ExpertId
            //group vote by vote.ExpertId into d
            //select new
            //{
            //    Expert = d.Key,
            //    Count = d.Count()
            //};

            //var experts = DataService.PerRequest.GroupMemberSet.Where(x => x.Id == group.Id && x.Expert).ToList();
            //DataService.PerRequest.ExpertSet.Where(x => x.GroupMember

            ExpertsList = new List <Group_Experts_ExpertViewModel>();
            foreach (var expert in experts.Take(3))
            {
                var user = expert.User;

                var expertViewModel = new Group_Experts_ExpertViewModel
                {
                    Id      = expert.Id,
                    UserId  = user.Id,
                    Name    = user.FirstName,
                    Surname = user.SurName,
                    City    = null,
                    Avatar  = ImageService.GetImageUrl <User>(user.Avatar),
                    Weight  = 0
                };
                ExpertsList.Add(expertViewModel);
            }
        }
Пример #2
0
        public Group_ExpertsViewModel(Guid groupId, Guid? userId)
        {
            SelfExpertTags = new List<TagViewModel>();
            ExpertsList = new List<Group_Experts_ExpertViewModel>();

            var group = GroupService.GetGroupByLabelOrId(groupId);
            GroupUrl = group.Url;

            if (userId.HasValue)
            {
                var uig = GroupService.UserInGroup(userId.Value, group);

                if (uig != null)
                {
                    IsMember = true;

                    if (uig.Expert != null)
                    {
                        IsExpert = true;
                        SelfExpertTags = uig.Expert.Tags.Select(x => new TagViewModel(x)).ToList();
                    }
                }
            }

            var currenUserId = Guid.Empty;
            if (UserContext.Current != null)
                currenUserId = UserContext.Current.Id;

            //TODO: дописать нормальный join, пока эксперты выводяться хаотично
            var experts = (from expert in DataService.PerThread.ExpertSet
                join groupMember in DataService.PerThread.GroupMemberSet
                on expert.GroupMember.Id equals groupMember.Id
                where groupMember.GroupId == groupId && groupMember.UserId != currenUserId
                select new { expert.Id, groupMember.User }).ToList();

            //join vote in DataService.PerRequest.ExpertVoteSet
            //on mergeExpert.Id equals vote.ExpertId
            //group vote by vote.ExpertId into d
            //select new
            //{
            //    Expert = d.Key,
            //    Count = d.Count()
            //};

            //var experts = DataService.PerRequest.GroupMemberSet.Where(x => x.Id == group.Id && x.Expert).ToList();
            //DataService.PerRequest.ExpertSet.Where(x => x.GroupMember

            ExpertsList = new List<Group_Experts_ExpertViewModel>();
            foreach (var expert in experts.Take(3))
            {
                var user = expert.User;

                var expertViewModel = new Group_Experts_ExpertViewModel
                {
                    Id = expert.Id,
                    UserId = user.Id,
                    Name = user.FirstName,
                    Surname = user.SurName,
                    City = null,
                    Avatar = ImageService.GetImageUrl<User>(user.Avatar),
                    Weight = 0
                };
                ExpertsList.Add(expertViewModel);
            }
        }