Beispiel #1
0
        public async Task LoadSessionAsync(Event @event)
        {
            IsBusy = true;
            _event = @event;
            var repositoryResponse = await _sessionRepository.GetSessionsAsync(_event);

            if (repositoryResponse.IsSuccesfull is false)
            {
                await ShutdownDialogHandleAsync("Nie można załadować sesji.");

                IsBusy = false;
                return;
            }

            var sessions = repositoryResponse.Value.ToList();

            if (sessions.IsNullOrEmpty())
            {
                var session  = new Session(@event, $"{Constants.Sessions.NewSessionNameBase}1");
                var response = await _sessionRepository.AddSessionAsync(session);

                sessions.Add(session);

                if (response.IsSuccesfull is false)
                {
                    await ShutdownDialogHandleAsync("Nie można załadować sesji.");

                    IsBusy = false;
                    return;
                }
            }

            CurrentSession = sessions.Find(x => x.Id == _applicationCache.LastChoosenSession) ?? sessions[0];
            IsBusy         = false;
        }
        public override async Task <bool> ConstructAsync()
        {
            var repositoryResponse = await _sessionRepository.GetSessionsAsync(_event).ConfigureAwait(false);

            if (repositoryResponse.IsSuccesfull is false)
            {
                return(false);
            }

            var sessions = repositoryResponse.Value.Select(session => new SessionViewModel(session)).OrderBy(x => x.Name).ToList();

            Sessions = new(sessions);

            var canAcceptRenaming = Sessions
                                    .ToObservableChangeSet()
                                    .AutoRefresh(x => x.Name)
                                    .ToCollection()
                                    .Select(vms =>
            {
                return(vms.All(vm => vm?.Name?.Length > 0 && vm?.Name?.Length < 41) &&
                       vms.AllDistinctBy(vm => vm.Name));
            });

            AcceptRenameSessionCommand = ReactiveCommand.CreateFromTask <SessionViewModel, Session>(AcceptRename, canAcceptRenaming);
            return(true);
        }