// GET: Relations
        public async Task <ActionResult> Index()
        {
            RelationShipsViewModel vm = new RelationShipsViewModel();

            vm.BlackList = await _relman.GetRelations(RelationshipStatus.Blacklisted, RelationDirection.IamIssuer);

            vm.Friends = await _relman.GetRelations(RelationshipStatus.Accepted);

            vm.Pendings = await _relman.GetRelations(RelationshipStatus.Pending);

            return(View(vm));
        }
Exemplo n.º 2
0
        public async Task <List <EventListItem> > ListEvents()
        {
            var relBlacklist = await _relations.GetRelations(RelationshipStatus.Blacklisted, RelationDirection.IamRecipient);

            var relFriends = await _relations.GetRelations(RelationshipStatus.Accepted);

            var blacklistedowners = relBlacklist.Select(r => r.UserId);
            var friendsOwners     = relFriends.Select(r => r.UserId);
            var usr = await GetCurrentUser();

            List <EventListItem> list = new List <EventListItem>();
            var allevents             = await _db.Events.Include(p => p.Owner).ToListAsync();



            //on filtre les events:
            // - ceux organisés par des organisateur qui ne m'on pas blacklist
            // - les sorties privées dont l'organisateur est un ami
            // - mes propres sorties
            var filteredevents = allevents.Where(e => blacklistedowners.All(t => t != e.Owner.Id) &&
                                                 (!e.IsPrivate || friendsOwners.Any(f => f == e.Owner.Id) ||
                                                  e.Owner.Id == usr.Id));

            foreach (var evt in filteredevents)
            {
                var parts = await _db.Participations.Include(p => p.Event).Where(f => f.Event.Id == evt.Id).CountAsync();

                var display = new EventListItem
                {
                    Date            = evt.Date,
                    EventId         = evt.Id,
                    MaxParticipants = evt.MaxSeats,
                    IsPrivate       = evt.IsPrivate,
                    Time            = evt.Time,
                    Participants    = parts,
                    Title           = evt.Title,
                    Owner           = evt.Owner.Pseudo,
                    OwnerId         = evt.Owner.Id
                };


                list.Add(display);
            }

            return(list.OrderByDescending(g => g.Date).ThenByDescending(g => g.Time).ToList());
        }