Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync()
        {
            var id = User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value;

            var events = IdentityClient.GetUserAgendaAsync(id).Result;

            if (events == null || !events.Any())
            {
                return(Page());
            }

            List <UserAgenda> list = new List <UserAgenda>();

            foreach (var item in events)
            {
                if (ApiClient.GetConferenceAsync(item.ConferenceId).Result != null && ApiClient.GetSessionAsync(item.SessionId).Result != null && ApiClient.GetTalkAsync(item.TalkId).Result != null)
                {
                    list.Add(item);
                }
                else
                {
                    await IdentityClient.DeleteUserAgenda(item.UserId, item.ConferenceId, item.SessionId, item.TalkId);
                }
            }

            if (list == null || !list.Any())
            {
                return(Page());
            }

            events = list;


            Entry = new List <AgendaEntry>();

            var l = events.GroupBy(x => x.ConferenceId);

            foreach (var conference in events.GroupBy(x => x.ConferenceId))
            {
                var conf = ApiClient.GetConferenceAsync(conference.Key).Result.GetConference;
                List <SessionResponse> sessions = new List <SessionResponse>();
                foreach (var session in conference.GroupBy(x => x.SessionId))
                {
                    var ses = ApiClient.GetSessionResponseAsync(session.Key).Result;
                    List <TalksResponse> tks = new List <TalksResponse>();

                    foreach (var talk in session)
                    {
                        tks.Add(ApiClient.GetTalkResponseAsync(talk.TalkId).Result);
                    }

                    ses.Talks = tks.ToArray();
                    sessions.Add(ses);
                }

                Entry.Add(new AgendaEntry
                {
                    Conference = conf,
                    Sessions   = sessions
                });
            }


            return(Page());
        }