Esempio n. 1
0
            public async Task <IEnumerable <PaymentDto> > GetAsync(PaymentsQuery query, CancellationToken token)
            {
                StudyRoomSession studyRoomSessionAlias = null;
                StudyRoom        studyRoomAlias        = null;

                Core.Entities.Tutor tutorAlias         = null;
                StudyRoomUser       studyRoomUserAlias = null;
                User studentAlias   = null;
                User tutorUserAlias = null;

                PaymentDto resultDto = null;

                var res = _session.QueryOver(() => studyRoomSessionAlias)
                          .JoinAlias(x => x.StudyRoom, () => studyRoomAlias)
                          .JoinEntityAlias(() => tutorAlias, () => studyRoomAlias.Tutor.Id == tutorAlias.Id)
                          .JoinEntityAlias(() => studyRoomUserAlias,
                                           () => studyRoomAlias.Id == studyRoomUserAlias.Room.Id &&
                                           tutorAlias.Id != studyRoomUserAlias.User.Id)
                          .JoinEntityAlias(() => studentAlias, () => studyRoomUserAlias.User.Id == studentAlias.Id)
                          .JoinEntityAlias(() => tutorUserAlias, () => tutorUserAlias.Id == tutorAlias.User.Id)
                          .Where(w => w.Receipt == null)
                          .Where(w => w.Duration.Value > TimeSpan.FromMinutes(10));

                if (!string.IsNullOrEmpty(query.Country))
                {
                    res = res.Where(w => studentAlias.Country == query.Country || tutorUserAlias.Country == query.Country);
                }

                return(await res.SelectList(sl =>
                                            sl.Select(s => s.Id).WithAlias(() => resultDto.StudyRoomSessionId)
                                            .Select(s => s.Price).WithAlias(() => resultDto.Price)
                                            .Select(Projections.Conditional(
                                                        Restrictions.IsNull(Projections.Property(() => tutorAlias.SellerKey)),
                                                        Projections.Constant(false),
                                                        Projections.Constant(true)
                                                        )).WithAlias(() => resultDto.IsSellerKeyExists)
                                            .Select(Projections.Conditional(
                                                        Restrictions.Eq(Projections.Property(() => studentAlias.PaymentExists), PaymentStatus.None),
                                                        Projections.Constant(false),
                                                        Projections.Constant(true)
                                                        )).WithAlias(() => resultDto.IsPaymentKeyExists)
                                            .Select(s => tutorAlias.Id).WithAlias(() => resultDto.TutorId)
                                            .Select(s => tutorUserAlias.Name).WithAlias(() => resultDto.TutorName)
                                            .Select(s => studentAlias.Id).WithAlias(() => resultDto.UserId)
                                            .Select(s => studentAlias.Name).WithAlias(() => resultDto.UserName)
                                            .Select(s => s.Created).WithAlias(() => resultDto.Created)
                                            .Select(s => s.Duration.Value).WithAlias(() => resultDto.Duration).WithAlias(() => resultDto.Duration)
                                            .Select(s => s.RealDuration.Value).WithAlias(() => resultDto.RealDuration).WithAlias(() => resultDto.RealDuration)
                                            //.Select(Projections.SqlFunction("COALESCE", NHibernateUtil.TimeSpan
                                            //               , Projections.Property<StudyRoomSession>(s => s.RealDuration.Value)
                                            //               , Projections.Property<StudyRoomSession>(s => s.Duration.Value))
                                            //).WithAlias(() => resultDto.Duration)
                                            .Select(Projections.Conditional(
                                                        Restrictions.IsNull(Projections.Property <StudyRoomSession>(s => s.RealDuration)),
                                                        Projections.Constant(false),
                                                        Projections.Constant(true)
                                                        )).WithAlias(() => resultDto.IsRealDurationExitsts)
                                            ).TransformUsing(Transformers.AliasToBean <PaymentDto>())
                       .ListAsync <PaymentDto>());
            }
Esempio n. 2
0
            public async Task <TutorActionsDto> GetAsync(TutorActionsQuery query, CancellationToken token)
            {
                var calendarFuture = _session.Query <GoogleTokens>()
                                     .Where(w => w.Id == query.UserId.ToString())
                                     .Take(1)
                                     .ToFutureValue();

                var hoursFuture = _session.Query <TutorHours>()
                                  .Where(w => w.Tutor.Id == query.UserId)
                                  .Take(1)
                                  .ToFutureValue();

                StudyRoom     studyRoomAlias     = null;
                StudyRoomUser studyRoomUserAlias = null;
                User          userAlias          = null;

                Core.Entities.Tutor tutorAlias      = null;
                AdminTutor          adminTutorAlias = null;



                var bookedSessionFuture = _session.QueryOver(() => studyRoomAlias)
                                          .JoinAlias(f => f.Users, () => studyRoomUserAlias)
                                          .JoinEntityAlias(() => userAlias, () => userAlias.Id == studyRoomUserAlias.User.Id)
                                          .JoinEntityAlias(() => tutorAlias, () => studyRoomAlias.Tutor.Id == tutorAlias.Id)
                                          .JoinEntityAlias(() => adminTutorAlias, () => tutorAlias.Id == adminTutorAlias.Tutor.Id)
                                          //.WhereRestrictionOn(() => studyRoomAlias.Tutor.Id).IsIn(adminList)
                                          .Where(w => userAlias.Id == query.UserId)
                                          .Where(w => adminTutorAlias.Id != null)
                                          .Select(s => s.Id)
                                          .Take(1)
                                          .FutureValue <Guid?>();

                var calendarShared = await calendarFuture.GetValueAsync(token) != null;

                var haveHours = await hoursFuture.GetValueAsync(token) != null;

                var bookedSession = await bookedSessionFuture.GetValueAsync(token) != null;

                var res = new TutorActionsDto()
                {
                    CalendarShared = calendarShared,
                    HaveHours      = haveHours,
                    BookedSession  = bookedSession
                };

                return(res);
            }