Пример #1
0
        public async Task <EventsListModel> Create()
        {
            string CurrentUserId = HttpContext.Current.User.Identity.GetUserId();

            notOwnedEventsList = new List <ShortEventModel>();
            ownedEventsList    = new List <ShortEventModel>();


            using (var db = new spontimeDatabaseEntities())
            {
                var user = await db.AspNetUsers.Include(u => u.EventInvite).Include("EventInvite.Events").FirstOrDefaultAsync(u => u.Id == CurrentUserId);

                List <EventInvite> invitesList = user.EventInvite.ToList();

                foreach (EventInvite inv in invitesList)
                {
                    if (inv.Events.OwnerId == CurrentUserId)
                    {
                        ownedEventsList.Add(new ShortEventModel(inv.Events));
                    }
                    else
                    {
                        notOwnedEventsList.Add(new ShortEventModel(inv.Events));
                    }
                }
            }
            return(this);
        }
Пример #2
0
        public async Task <MyEventsModel> CreateAsync()
        {
            myEventsList = new List <EventModel>();
            String CurrentUserId = HttpContext.Current.User.Identity.GetUserId();

            using (var db = new spontimeDatabaseEntities())
            {
                var currUserQuery = (from usr in db.AspNetUsers.Include(e => e.EventInvite) where usr.Id == CurrentUserId select usr);
                currUserQuery.Include("EventInvites.Events");
                // currUserQuery.Include("EventInvites.Events.EventInvites");
                var currUser = await currUserQuery.FirstOrDefaultAsync();

                foreach (var inv in currUser.EventInvite)
                {
                    myEventsList.Add(inv.Events);
                }
            }
        }