Ejemplo n.º 1
0
 public VoteController(IBirthdayPeopleService birthdayPeople, IVoteService voteData, IPresentService presentData, IBirthdayData dbData)
 {
     this.birthdayData = birthdayPeople;
     this.voteData = voteData;
     this.presentData = presentData;
     this.dbData = dbData;
 }
Ejemplo n.º 2
0
        public IQueryable<Vote> GetAvailableVotes(IBirthdayData dbData, string currentUser)
        {
            //var availableVotes = this.data.All()
            //    .Join(birthdayData.PresentsVotes.All(),
            //            v => v.Id,
            //            pv => pv.VoteId,
            //            (v, pv) => new { v, pv })
            //    //(v, pv) => new Vote
            //    //{
            //    //    VoteId = v.Id,
            //    //    BirthdayPerson = v.BirthdayPersonId,
            //    //    Initiator = v.InitiatorId,
            //    //    SytartDate = v.StartDate,
            //    //    EndDate = v.EndDate,
            //    //    UserId = pv.UserId
            //    //})
            //  .Where(av => av.v.EndDate == null &&
            //      av.v.BirthdayPersonId != currentUser &&
            //      av.pv.UserId != currentUser)
            //      .ToList();
            //      //.Select(av => new Vote
            //      //{
            //      //    Id = av.v.Id,
            //      //    InitiatorId = av.v.InitiatorId,
            //      //    Initiator = av.v.Initiator,
            //      //    BirthdayPersonId = av.v.BirthdayPersonId,
            //      //    BirthdayPerson = av.v.BirthdayPerson,
            //      //    StartDate = av.v.StartDate,
            //      //    EndDate = av.v.EndDate,
            //      //    Year = av.v.Year
            //      //});

            //var availableVotes = dbData.Votes.All()
            //       .Join(dbData.PresentsVotes.All().Where(pv => pv.UserId != currentUser),
            //             v => v.Id,
            //             pv => pv.VoteId,
            //             (v, pv) => v)
            //        .Where(av => av.EndDate == null && av.BirthdayPersonId != currentUser);

            var givenPresentVote = dbData.PresentsVotes.All()
                .Where(pv => pv.UserId == currentUser)
                .Select(pv => pv.VoteId)
                .ToArray();

            var availableVotes = this.data.All()
                .Where(v => (v.EndDate == null) &&
                            (v.BirthdayPerson.Id != currentUser) &&
                            (!givenPresentVote.Contains(v.Id)));

            return availableVotes;
        }
Ejemplo n.º 3
0
 public HomeController(IBirthdayData data)
 {
     this.data = data;
 }