Ejemplo n.º 1
0
        public async Task <ExpertConnectionsRes> GetExpertConnections(ExpertConnectionsReq req, DatabaseContext context)
        {
            var currentUserData = this._currentUserService.GetCurrentUserData();

            if (req.ExpertProfileId != currentUserData.ExpertProfileId)
            {
                throw new NotYourProfileException();
            }

            var connections = await context.Connections
                              .Where(c => c.ConnectionStatus != ConnectionStatuses.Canceled)
                              .Where(c => c.ExpertProfileId == req.ExpertProfileId)
                              .OrderBy(c => c.Vacancy.StartTime)
                              .Select(c => new ExpertConnectionsRes.Connection
            {
                Id      = c.Id,
                Type    = c.ConnectionType,
                Status  = c.ConnectionStatus,
                Vacancy = new ExpertConnectionsRes.Vacancy
                {
                    Id        = c.Vacancy.Id,
                    Languages = c.Vacancy.VacancyLanguages.Select(vl => new ExpertConnectionsRes.Language {
                        Id = vl.Language.Id, Name = vl.Language.Name
                    }).ToArray(),
                    Event = new ExpertConnectionsRes.Event
                    {
                        Id           = c.Vacancy.Event.Id,
                        Name         = c.Vacancy.Event.Name,
                        LogoImageUrl = c.Vacancy.Event.LogoImageUrl,
                        Segment      = c.Vacancy.Event.SegmentId != null
                ? new ExpertConnectionsRes.Segment {
                            Id = c.Vacancy.Event.Segment.Id, Name = c.Vacancy.Event.Segment.Name
                        }
                : null,
                        Format = c.Vacancy.Event.EventFormatId != null
                ? new ExpertConnectionsRes.EventFormat {
                            Id = c.Vacancy.Event.EventFormat.Id, Name = c.Vacancy.Event.EventFormat.Name
                        }
                : null,
                        Type = c.Vacancy.Event.EventTypeId != null
                ? new ExpertConnectionsRes.EventType {
                            Id = c.Vacancy.Event.EventType.Id, Name = c.Vacancy.Event.EventType.Name
                        }
                : null,
                        City = c.Vacancy.Event.CityId != null
                ? new ExpertConnectionsRes.City {
                            Id = c.Vacancy.Event.City.Id, Name = c.Vacancy.Event.City.Name
                        }
                : null,
                        Address               = c.Vacancy.Event.Address,
                        StartTime             = c.Vacancy.Event.StartTime,
                        EndTime               = c.Vacancy.Event.EndTime,
                        EstimatedGuestsCount  = c.Vacancy.Event.EstimatedGuestsCount,
                        EstimatedAverageCheck = c.Vacancy.Event.EstimatedAverageCheck,
                        TotalCooksCount       = c.Vacancy.Event.Vacancies.Where(vacancy => vacancy.SpecialityId == SpecialityIds.Cook).Select(vv => vv.Amount ?? 0).DefaultIfEmpty(0).Sum(),
                        TotalBarmansCount     = c.Vacancy.Event.Vacancies.Where(vacancy => vacancy.SpecialityId == SpecialityIds.Barman).Select(vv => vv.Amount ?? 0).DefaultIfEmpty(0).Sum(),
                        TotalWaitersCount     = c.Vacancy.Event.Vacancies.Where(vacancy => vacancy.SpecialityId == SpecialityIds.Waiter).Select(vv => vv.Amount ?? 0).DefaultIfEmpty(0).Sum(),
                        ConnectedCooksCount   = c.Vacancy.Event.Vacancies.Where(vacancy => vacancy.SpecialityId == SpecialityIds.Cook).SelectMany(vv => vv.Connections).Count(conn => conn.ConnectionStatus == ConnectionStatuses.Connected),
                        ConnectedBarmansCount = c.Vacancy.Event.Vacancies.Where(vacancy => vacancy.SpecialityId == SpecialityIds.Barman).SelectMany(vv => vv.Connections).Count(conn => conn.ConnectionStatus == ConnectionStatuses.Connected),
                        ConnectedWaitersCount = c.Vacancy.Event.Vacancies.Where(vacancy => vacancy.SpecialityId == SpecialityIds.Waiter).SelectMany(vv => vv.Connections).Count(conn => conn.ConnectionStatus == ConnectionStatuses.Connected),
                        Company               = new ExpertConnectionsRes.Company
                        {
                            Id   = c.Vacancy.Event.Company.Id,
                            Name = c.Vacancy.Event.Company.Name,
                            ThumbnailImageUrl = c.Vacancy.Event.Company.ThumbnailImageUrl,
                            Rating            =
                                (
                                    4.5 +
                                    c.Vacancy.Event.Company.Events
                                    .SelectMany(ee => ee.Vacancies)
                                    .SelectMany(vv => vv.Connections)
                                    .Where(cc => cc.FeedbackForCompany != null)
                                    .Select(cc => cc.FeedbackForCompany.Rating)
                                    .DefaultIfEmpty(0).Sum()
                                ) /
                                (
                                    1 +
                                    c.Vacancy.Event.Company.Events
                                    .SelectMany(ee => ee.Vacancies)
                                    .SelectMany(vv => vv.Connections)
                                    .Where(cc => cc.FeedbackForCompany != null)
                                    .Count()
                                ),
                        },
                    },

                    Speciality = c.Vacancy.Speciality != null
              ? new ExpertConnectionsRes.Speciality
                    {
                        Id             = c.Vacancy.Speciality.Id,
                        Name           = c.Vacancy.Speciality.Name,
                        Specialization = c.Vacancy.SpecializationId != null
                  ? new ExpertConnectionsRes.Specialization
                        {
                            Id   = c.Vacancy.Specialization.Id,
                            Name = c.Vacancy.Specialization.Name
                        }
                  : null,
                        SkillsGroups = c.Vacancy.VacancySkills.Select(vc => vc.Skill).Where(s => s.SpecialityId == c.Vacancy.SpecialityId).GroupBy(s => s.GroupName)
                                       .Select(g =>
                                               new ExpertConnectionsRes.SkillsGroup
                        {
                            Name   = g.Key,
                            Skills = g.Select(s => new ExpertConnectionsRes.Skill {
                                Id = s.Id, Name = s.Name
                            }).ToArray(),
                        }
                                               ).ToArray()
                    }
              : null,
                    Experience = c.Vacancy.ExperienceOptionId != null
              ? new ExpertConnectionsRes.Experience {
                        Id = c.Vacancy.ExperienceOption.Id, Name = c.Vacancy.ExperienceOption.Name
                    }
              : null,
                    StartTime    = c.Vacancy.StartTime,
                    WorkingHours = c.Vacancy.WorkingHours,
                    RatePerHour  = c.Vacancy.RatePerHour,
                },
                FeedbackForExpert = c.FeedbackForExpert != null
            ? new ExpertConnectionsRes.Feedback
                {
                    Id          = c.FeedbackForExpert.Id,
                    Rating      = c.FeedbackForExpert.Rating,
                    CommentHtml = c.FeedbackForExpert.CommentHtml,
                }
            : null,
                FeedbackForCompany = c.FeedbackForCompany != null
            ? new ExpertConnectionsRes.Feedback
                {
                    Id          = c.FeedbackForCompany.Id,
                    Rating      = c.FeedbackForCompany.Rating,
                    CommentHtml = c.FeedbackForCompany.CommentHtml,
                }
            : null
            }).ToArrayAsync();

            var res = new ExpertConnectionsRes
            {
                Connections = connections
            };

            return(res);
        }
Ejemplo n.º 2
0
        public async Task <ExpertConnectionsRes> GetActiveExpertConnections(DatabaseContext context)
        {
            var currentUserId = this._currentUserService.GetCurrentUserData().Id;

            var res = new ExpertConnectionsRes
            {
                Connections = await context.Connections
                              .Where(c => c.ExpertProfile.UserId == currentUserId)
                              .Where(c => c.ConnectionStatus == ConnectionStatuses.Connected)
                              .Where(c => c.FeedbackForCompanyId == null)
                              .Select(c => new ExpertConnectionsRes.Connection
                {
                    Id                = c.Id,
                    Type              = c.ConnectionType,
                    Status            = c.ConnectionStatus,
                    FeedbackForExpert = c.FeedbackForExpert != null
            ? new ExpertConnectionsRes.Feedback
                    {
                        Id          = c.FeedbackForExpert.Id,
                        Rating      = c.FeedbackForExpert.Rating,
                        CommentHtml = c.FeedbackForExpert.CommentHtml,
                    }
            : null,
                    FeedbackForCompany = c.FeedbackForCompany != null
            ? new ExpertConnectionsRes.Feedback
                    {
                        Id          = c.FeedbackForCompany.Id,
                        Rating      = c.FeedbackForCompany.Rating,
                        CommentHtml = c.FeedbackForCompany.CommentHtml,
                    }
            : null,
                    NewIncomingMessagesCount = c.ChatMessages.Count(m => m.ReceiveTime == null && m.Direction == ChatMessageDirections.VacancyToExpert),
                    LastMessage = c.ChatMessages
                                  .Select(m => new ExpertConnectionsRes.LastMessage
                    {
                        Id   = m.Id,
                        Body = m.Body,
                        Time = m.ReceiveTime ?? m.SendTime
                    })
                                  .OrderByDescending(m => m.Time)
                                  .FirstOrDefault(),
                    Vacancy = new ExpertConnectionsRes.Vacancy
                    {
                        Id         = c.Vacancy.Id,
                        Speciality = c.Vacancy.SpecialityId != null
              ? new ExpertConnectionsRes.Speciality
                        {
                            Id             = c.Vacancy.Speciality.Id,
                            Name           = c.Vacancy.Speciality.Name,
                            Specialization = c.Vacancy.SpecializationId != null
                  ? new ExpertConnectionsRes.Specialization
                            {
                                Id   = c.Vacancy.Specialization.Id,
                                Name = c.Vacancy.Specialization.Name,
                            }
                  : null,
                        }
              : null,
                        Event = new ExpertConnectionsRes.Event
                        {
                            Id           = c.Vacancy.Event.Id,
                            Name         = c.Vacancy.Event.Name,
                            LogoImageUrl = c.Vacancy.Event.LogoImageUrl,
                            Company      = new ExpertConnectionsRes.Company
                            {
                                Id   = c.Vacancy.Event.Company.Id,
                                Name = c.Vacancy.Event.Company.Name,
                                ThumbnailImageUrl = c.Vacancy.Event.Company.ThumbnailImageUrl,
                                IsOnline          = this.IsOnline(c.Vacancy.Event.Company.UserId),
                                LastSeenTime      = c.Vacancy.Event.Company.User.LastSeenTime,
                            }
                        }
                    }
                }).ToArrayAsync()
            };

            return(res);
        }