예제 #1
0
        private async Task Login(MobileServiceAuthenticationProvider provider)
        {
            var user = await _authenticationService.Login(provider);

            var userName = await GetIsOauthUserRegistered(user.UserId);

            await _databaseService.SaveCurrentUserAsync(new User { UserName = userName });

            await _databaseService.DeleteAllScheduledConferencesAsync();

            var conferenceDtos = await _remoteConferenceService.LoadScheduledConferencesAsync(userName);

            foreach (var conferenceDto in conferenceDtos)
            {
                var dto = conferenceDto;
                dto.IsAddedToSchedule = true;
                var conference = await TaskEx.Run(() => Mapper.Map <Conference> (dto));

                await _databaseService.SaveConferenceAsync(conference);

                foreach (var sessionDto in dto.Sessions)
                {
                    SessionDto dto1    = sessionDto;
                    var        session = await TaskEx.Run(() => Mapper.Map <Session>(dto1));

                    session.ConferenceId = conference.Id;
                    await _databaseService.SaveSessionAsync(session);

                    foreach (var speakerDto in sessionDto.Speakers)
                    {
                        SpeakerDto speakerDto1 = speakerDto;
                        var        speaker     = await TaskEx.Run(() => Mapper.Map <Speaker>(speakerDto1));

                        speaker.SessionId = session.Id;
                        await _databaseService.SaveSpeakerAsync(speaker);
                    }
                }
            }

            ShowViewModel <ConferencesTabViewModel> ();
        }
        public async Task LoadConferencesAsync(LoadRequest loadRequest)
        {
            this.AreConferencesLoading = true;

            _currentUser = await _databaseService.LoadCurrentUserAsync();

            if (_currentUser != null)
            {
                var scheduledConferences = await _databaseService.LoadScheduledConferencesAsync();

                if (!scheduledConferences.Any() || loadRequest == LoadRequest.Refresh)
                {
                    await _databaseService.DeleteAllScheduledConferencesAsync();

                    var scheduledConferenceDtos = await _conferenceService.LoadScheduledConferencesAsync(_currentUser.UserName);

                    foreach (var scheduledConferenceDto in scheduledConferenceDtos)
                    {
                        var dto = scheduledConferenceDto;
                        var scheduledConference = await TaskEx.Run(() => Mapper.Map <Conference> (dto));

                        await _databaseService.SaveConferenceAsync(scheduledConference);

                        //foreach (var sessionDto in scheduledConferenceDto.Sessions)
                        //{
                        //	SessionDto dto1 = sessionDto;
                        //	var session = await TaskEx.Run(() => Mapper.Map<Session>(dto1));
                        //	session.ConferenceId = scheduledConference.Id;
                        //	await _databaseService.SaveSessionAsync(session);
                        //}
                    }

                    scheduledConferences = await _databaseService.LoadScheduledConferencesAsync();
                }

                this.Conferences = scheduledConferences;
            }

            this.AreConferencesLoading = false;
        }