Пример #1
0
        public async Task <RoomViewModel?> JoinRoomAsync()
        {
            if (string.IsNullOrWhiteSpace(AccessCode))
            {
                await SnackbarViewModel.Enqueue("Uzupełnij kod dostępu.");

                return(null);
            }

            IsBusy = true;

            var response = await _roomsService.JoinRoomAsync(AccessCode !);

            IsBusy = false;

            if (response.IsSuccesfull is false)
            {
                await SnackbarViewModel.Enqueue("Nie można dołaczyć do pokoju ponieważ już się rozpoczął lub nie istnieje.");

                return(null);
            }

            SnackbarViewModel.Disposed = true;
            return(new RoomViewModel(
                       isAdmin: false,
                       response.Value !,
                       _roomsService));
        }
Пример #2
0
        public ExportsViewModel(
            Session session,
            ObservableCollection <SolveViewModel> solves,
            ISolvesJsonExporter?solvesJsonExporter = null,
            ISolvesCsvExporter?solvesCsvExporter   = null,
            ISolvesRepository?solvesRepository     = null)
        {
            _session            = session;
            _solveViewModels    = solves;
            _solves             = solves.Select(x => x.Model).ToList();
            _solvesJsonExporter = solvesJsonExporter ?? Ioc.GetService <ISolvesJsonExporter>();
            _solvesCsvExporter  = solvesCsvExporter ?? Ioc.GetService <ISolvesCsvExporter>();
            _solvesRepository   = solvesRepository ?? Ioc.GetService <ISolvesRepository>();

            SnackbarViewModel = new SnackbarViewModel(500, 96, 4);
            ExportJsonCommand = ReactiveCommand.CreateFromTask(ExportJsonAsync);
            ImportJsonCommand = ReactiveCommand.CreateFromTask(ImportJsonAsync);
            ExportCsvCommand  = ReactiveCommand.CreateFromTask(ExportCsvAsync);
            ImportCsvCommand  = ReactiveCommand.CreateFromTask(ImportCsvAsync);

            ExportJsonCommand.ThrownExceptions.Subscribe(async(e) => await Catch(e, "Podczas ekspotu wystąpił błąd."));
            ImportJsonCommand.ThrownExceptions.Subscribe(async(e) => await Catch(e, "Podczas importu wystąpił błąd."));
            ExportCsvCommand.ThrownExceptions.Subscribe(async(e) => await Catch(e, "Podczas ekspotu wystąpił błąd."));
            ImportCsvCommand.ThrownExceptions.Subscribe(async(e) => await Catch(e, "Podczas importu wystąpił błąd."));

            OkCommand = ReactiveCommand.Create(() => { SnackbarViewModel.Disposed = true; });

            ShowJsonFileDialog = new Interaction <Unit, string[]>();
            ShowCsvFileDialog  = new Interaction <Unit, string[]>();
        }
Пример #3
0
        public AuthenticationViewModel(IAuthenticationService authenticationService, IRegionManager regionManager, IEventAggregator eventAggregator, IRepository repo)
            : base(regionManager, eventAggregator, repo)
        {
            _authenticationService = authenticationService;

            Snackbar = new SnackbarViewModel();

            LoginCommand = new DelegateCommand <PasswordBox>(Login);
        }
Пример #4
0
        public SolvesListViewModel(
            SnackbarViewModel snackbarViewModel,
            ISolvesRepository?solvesRepository = null)
        {
            _snackbarViewModel = snackbarViewModel;
            _solvesRepository  = solvesRepository ?? Ioc.GetService <ISolvesRepository>();

            Solves = new ObservableCollection <SolveViewModel>();
            Solves.CollectionChanged += UpdateIndexesAsync;

            DeleteItemCommand = ReactiveCommand.CreateFromTask <SolveViewModel>(DeleteSolveAsync);
        }
Пример #5
0
 public SessionSummaryViewModel(
     SnackbarViewModel snackbarViewModel,
     ISessionsRepository?sessionRepository        = null,
     IApplicationCache?applicationCache           = null,
     IApplicationCacheSaver?applicationCacheSaver = null)
 {
     _svgToBitmapConverter   = new SvgToBitmapConverter(100);
     _snackbarViewModel      = snackbarViewModel;
     _sessionRepository      = sessionRepository ?? Ioc.GetService <ISessionsRepository>();
     _applicationCache       = applicationCache ?? Ioc.GetService <IApplicationCache>();
     _applicationCacheSaver  = applicationCacheSaver ?? Ioc.GetService <IApplicationCacheSaver>();
     ChangeSessionCommand    = ReactiveCommand.CreateFromTask(ChangeSessionAsync);
     ShowSessionChangeDialog = new Interaction <SessionChangeViewModel, SessionViewModel?>();
 }
Пример #6
0
 public RoomCreationViewModel(
     IRoomsService?roomsService = null)
 {
     _roomsService     = roomsService ?? Ioc.GetService <IRoomsService>();
     ScramblesAmount   = string.Empty;
     AllEvents         = Core.Constants.Events.Predefined;
     CreateRoomCommand = ReactiveCommand.CreateFromTask(CreateRoomAsync);
     JoinRoomCommand   = ReactiveCommand.CreateFromTask(JoinRoomAsync);
     CancelCommand     = ReactiveCommand.Create(() =>
     {
         SnackbarViewModel.Disposed = true;
     });
     AccessCode        = "";
     SnackbarViewModel = new SnackbarViewModel(height: 96);
 }
Пример #7
0
        private static void RenderSnackbar(SnackbarViewModel model, TagBuilderEx parent)
        {
            using (TagBuilderEx alert = parent.CreateInnerTag("div"))
            {
                alert.AddCssClasses("center-block", "alert", "alert-dismissible");
                alert.AddCssClass("alert-" + model.Type.ToString());
                alert.MergeAttribute("data-snackbar-timeout", model.Timeout.ToString());
                alert.MergeAttribute("role", "alert");

                using (TagBuilderEx content = alert.CreateInnerTag("span"))
                {
                    content.AddCssClass("alert-content");
                    content.InnerHtml = model.Message;
                }
            }
        }
Пример #8
0
        public async Task <RoomViewModel?> CreateRoomAsync()
        {
            if (SelectedEvent is null)
            {
                await SnackbarViewModel.Enqueue("Wybierz event.");

                return(null);
            }

            if (string.IsNullOrEmpty(ScramblesAmount))
            {
                await SnackbarViewModel.Enqueue("Uzupełnij liczbę scrambli.");

                return(null);
            }
            var scramblesAmountParsed = int.TryParse(ScramblesAmount, out var scramblesAmount) &&
                                        3 <= scramblesAmount &&
                                        scramblesAmount <= 20;

            if (scramblesAmountParsed is false)
            {
                await SnackbarViewModel.Enqueue("Liczba scrambli musi być w przedziale [3, 20].");

                return(null);
            }

            IsBusy = true;

            var response = await _roomsService.CreateRoomAsync(SelectedEvent !, scramblesAmount);

            IsBusy = false;

            if (response.IsSuccesfull is false)
            {
                await SnackbarViewModel.Enqueue("Podczas można utworzyć pokoju. Podczas łączenia z serwerem wystąpił problem.");

                return(null);
            }

            SnackbarViewModel.Disposed = true;
            return(new RoomViewModel(
                       isAdmin: true,
                       response.Value !,
                       _roomsService));
        }
        private static ActionResult WithSnackbar(ActionResult actionResult, SnackbarType messageType, int timeout, string format, params object[] values)
        {
            // retrieve the current instance of controller that I already stored it in HttpContext.Items while
            // controller factory class execute CreateController method.
            var controller = HttpContext.Current.Items[BaseController.CurrentControllerInstanceKey] as BaseController;

            if (controller.Request.IsAjaxRequest())
            {
                controller.Response.AddHeader(BaseController.SnackbarMessageHeaderKey, controller.Server.UrlEncode(string.Format(format, values)));
                controller.Response.AddHeader(BaseController.SnackbarMessageTypeHeaderKey, messageType.ToString());
                controller.Response.AddHeader(BaseController.SnackbarMessageTimeoutHeaderKey, timeout.ToString());
                return(actionResult);
            }

            var snackBarModel = new SnackbarViewModel(string.Format(format, values), messageType, timeout);

            // add new SnackbarViewModel instance to the LayoutModel which will be read from _Layout.cshtml while rendered.
            controller.LayoutModel.Snackbars.Add(snackBarModel);

            return(actionResult);
        }
Пример #10
0
        public SolveViewModel(
            Solve solve,
            SnackbarViewModel snackbarViewModel,
            ISolvesRepository solvesSaver)
        {
            _snackbarViewModel = snackbarViewModel;
            _solvesRepository  = solvesSaver;

            Model    = solve;
            Time     = solve.TimeAsSpan;
            Flag     = solve.Flag;
            Date     = solve.Date;
            Scramble = solve.Scramble;

            SolveFlagsViewModel = new SolveFlagsViewModel(solve.Flag);

            EditSolveCommand = ReactiveCommand.CreateFromTask <Window>(EditSolve);
            AcceptCommand    = ReactiveCommand.CreateFromTask <Window>(SaveFlag);

            UpdateSummary();
        }
Пример #11
0
        public LoginViewModel(
            ILoginRepository?loginRepository = null,
            IValueConverter <RepositoryResponseStatus, string>?repositoryResponseValueConverter = null)
        {
            _loginRepository      = loginRepository ?? Ioc.GetService <ILoginRepository>();
            _loginStatusConverter = repositoryResponseValueConverter ?? new LoginStatusConverter();

            SnackbarViewModel = new SnackbarViewModel {
                Message = String.Empty
            };

            var acceptLoginEnabled = this.WhenAnyValue(
                x => x.LoginName,
                x => x.LoginPassowd,
                (name, password) => !string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(password));

            RegisterCommand      = ReactiveCommand.CreateFromTask(Register);
            AcceptLoginCommand   = ReactiveCommand.CreateFromTask(AcceptLoginAsync, acceptLoginEnabled);
            ContinueLocalCommand = ReactiveCommand.CreateFromTask(ContinueLocalAsync);

            ShowRegisterDialog   = new Interaction <RegisterViewModel, Unit>();
            ShowMainWindowDialog = new Interaction <MainWindowViewModel, Unit>();
        }
Пример #12
0
 private async Task Catch(Exception e, string message)
 {
     IsBusy = false;
     await SnackbarViewModel.Enqueue(message);
 }