Пример #1
0
        public async Task LoadAsync()
        {
            //await LoadMemberLookupAsync();
            //await NavigationViewModel.LoadAsync();

            if (5 < LoginOfficeId.Length)
            {
                try
                {
                    var temp = await _memberRepository.GetByOfficeIdAsync(LoginOfficeId);

                    LoggedMember = new MemberWrapper(temp);

                    if (LoggedMember.IpNumber == GetIpNumber())
                    {
                        LoginOfficeId = LoggedMember.OfficeId;
                        Settings.Default.currentUserOfficeId = LoginOfficeId;
                        Settings.Default.Save();
                    }
                }
                catch
                {
                    _messageDialogService.ShowInfoDialog("로그인 실패");

                    return;
                }
            }
        }
Пример #2
0
        private async void OnRentExecute()
        {
            var selectedCar = SelectedCar;

            var preflight = await _preflightService.Preflight(SelectedCar.Model);

            if (preflight.Code == PreflightResultCode.BLOCKED)
            {
                _messageDialogService.ShowInfoDialog(preflight.Message);
                Cars.Remove(SelectedCar);
                SelectedCar = null;
                return;
            }

            var result = _messageDialogService.ShowOkCancelDialog(preflight.Message, "Confirmation");

            if (result == MessageDialogResult.OK)
            {
                var booking = new Booking {
                    CarId = SelectedCar.Model.Id, UserId = _currentUser.Id, RentedAt = DateTime.Now
                };
                _bookingRepository.MakeRent(booking);
                await _bookingRepository.SaveAsync();

                Cars.Remove(SelectedCar);
                SelectedCar = null;
                _messageDialogService.ShowInfoDialog($"You successfuly rented {selectedCar.Name}");
            }
        }
Пример #3
0
        private async void OnOpenDetailView(OpenDetailViewEventArgs args)
        {
            var detailViewModel = DetailViewModels.SingleOrDefault(vm => vm.Id == args.Id &&
                                                                   vm.GetType().Name == args.ViewModelName);

            if (detailViewModel == null)
            {
                detailViewModel = _detailViewModelCreator[args.ViewModelName];
                try
                {
                    await detailViewModel.LoadAsync(args.Id);
                } catch
                {
                    _messageDialogService.ShowInfoDialog("Could not load entity, maybe it was deleted in the meantime by" +
                                                         "another uuser.");
                    await NavigationViewModel.LoadAsync();

                    return;
                }
                DetailViewModels.Add(detailViewModel);
            }

            if (SelectedDetailViewModel != null && SelectedDetailViewModel.HasChanges)
            {
                var result = _messageDialogService.ShowOkCancelDialog("You've made changes. Navigate away?", "Question");
                if (result == MessageDialogResult.CANCEL)
                {
                    return;
                }
            }
            SelectedDetailViewModel = detailViewModel;
        }
        private async void OnOpenDetailView(OpenDetailViewEventArgs args)
        {
            var detailViewModel = DetailViewModels
                                  .SingleOrDefault(vm => vm.Id == args.Id &&
                                                   vm.GetType().Name == args.ViewModelName);

            if (detailViewModel == null)
            {
                detailViewModel = _detailViewModelCreator[args.ViewModelName];
                try
                {
                    await detailViewModel.LoadAsync(args.Id);
                }
                catch (Exception)
                {
                    await _messageDialoagService.ShowInfoDialog("Could not load the entity, " +
                                                                "maybe it was deleted by another user. " +
                                                                "The navigation view will be refreshed.");

                    await NavigationViewModel.LoadAsync();

                    return;
                }

                DetailViewModels.Add(detailViewModel);
            }

            SelectedDetailViewModel = detailViewModel;
        }
Пример #5
0
        protected async Task OnSaveOptimisticConcurnceyAsyc(Func <Task> SaveFunc, Action AfterSaveAction)
        {
            try
            {
                await SaveFunc();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var databasevalue = ex.Entries.Single().GetDatabaseValues();
                if (databasevalue == null)
                {
                    MessageDialogeService.ShowInfoDialog("this entity was been deleted By another user");
                    RaiseDetailDeletedEvent(Id);
                    return;
                }
                var res = MessageDialogeService.ShowOkCancelDialog("The entity has been changed in by another meantime by someone else. Click ok to save your changes anyway, click Cancel to reload the entity from the database", "Question");
                if (res == MessageDialogResult.Ok)
                {
                    var entry = ex.Entries.Single();
                    entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                    await SaveFunc();
                }
                else
                {
                    await ex.Entries.Single().ReloadAsync();
                    await LoadAsync(Id);
                }
            }


            AfterSaveAction();
        }
Пример #6
0
        /// <summary>
        /// If the ViewModel, identified by the combination of the event arguments, not already exists in the ViewModels list,
        /// then a new Viewmodel (NavigationViewModel or DetailViewModel) is created from the event arguments,
        /// and LoadAsync function of the created ViewModel is called
        /// and ViewModel is added tio ViewModels list
        /// and SelectedViewModel is set to ViewModel.
        /// </summary>
        /// <param name="eventOpenViewModelArgs">Id and Name of the ViewModel</param>
        private async void OnEventOpenNavigationOrDetailViewModel(EventOpenNavigationOrDetailViewModelArgs eventOpenViewModelArgs)
        {
            IsBusy = true;

            var viewModel = ViewModels.SingleOrDefault(dvm
                                                       => dvm.Id == eventOpenViewModelArgs.Id &&
                                                       dvm.Name == eventOpenViewModelArgs.ViewModelName);

            //ViewModel does not exist in ViewModels
            //-> create, call ViewModels LoadAsync function and add ViewModel to ViewModels
            if (viewModel == null)
            {
                viewModel = _viewModelFactory.Create(eventOpenViewModelArgs.ViewModelName);
                bool loadAsyncSucessful = await viewModel.LoadAsync(eventOpenViewModelArgs.Id);

                //bool loadAsyncSucessful = await Task.Run(() => viewModel.LoadAsync(eventOpenViewModelArgs.Id));

                if (loadAsyncSucessful)
                {
                    ViewModels.Add(viewModel);


                    //Set the focus to the selected ViewModel
                    SelectedViewModel = viewModel;

                    //Hide the MainNavigationView:
                    IsMainNavigationViewShown = false;
                }
                else
                {
                    _messageDialogService.ShowInfoDialog("Entry could not be loaded as it might have been deleted. Displayed Entries are refreshed.", "Information");
                }
            }
            IsBusy = false;
        }
Пример #7
0
 protected async Task SaveWithOptimisticConcurrencyAsync(Func <Task> saveFunc, Action afterSaveAction)
 {
     try
     {
         await saveFunc();
     }
     catch (DbUpdateConcurrencyException ex)
     {
         var databaseValues = ex.Entries.Single().GetDatabaseValues();
         if (databaseValues == null)
         {
             MessageDialogService.ShowInfoDialog("The entity has been deleted by another user..!");
             RaiseDetailDeletedEvent(Id);
             return;
         }
         var result = MessageDialogService.ShowOkCancelDialog("The entity has been changed in the meantime by someone else."
                                                              + "Click OK to save your changes anyway, click CANCEL to reload entity from the database...", "Question");
         if (result == MessageDialogResult.OK)
         {
             //update original values with databse values
             var entry = ex.Entries.Single();
             entry.OriginalValues.SetValues(entry.GetDatabaseValues());
             await saveFunc();
         }
         else
         {
             await ex.Entries.Single().ReloadAsync();
             await LoadAsync(Id);
         }
     }
     afterSaveAction();
 }
Пример #8
0
        private void OnAddFiles()
        {
            string[] filePath = FileData.GetFiles();

            bool errorFound = false;

            foreach (var file in filePath)
            {
                if (FileData.IsAvailableFileExtention(file) && !IsFileAlreadyAdded(file))
                {
                    try
                    {
                        var result = AddDataFromFileIfExistsToDatabase(file);
                        if (result == true)
                        {
                            Files.Add(new NavigationItemViewModel(file, _eventAggregator));
                        }
                        else
                        {
                            _messageDailogService.ShowInfoDialog($"Plik {file} nie zawiera poprawnych danych, dlatego nie został dodany");
                        }
                    }
                    catch (FileFormatException Ffe)
                    {
                        //it shoudn't happend
                        _messageDailogService.ShowInfoDialog(Ffe.Message);
                    }
                    catch (Exception)
                    {
                        _messageDailogService.ShowInfoDialog($"Problem podczas otwierania lub odczytywania danych z pliku {file}. Sprawdź czy plik zawiera poprawne dane");
                    }
                }
                else
                {
                    errorFound = true;
                }
            }
            if (errorFound)
            {
                _messageDailogService.ShowInfoDialog("Co najmniej jeden z wybranych plików został już dodany lub posiada niepraidłowe rozszerzenie ");
            }
        }
 private bool ValidateSelectedClientId()
 {
     if (SelectedClientId == "")
     {
         return(false);
     }
     else if (!Request.ValidateClientId(SelectedClientId))
     {
         _messageDailogService.ShowInfoDialog("Wybrany identyfikator klienta jest nieprawidłowy");
         return(false);
     }
     return(true);
 }
Пример #10
0
        private async void CheckLogin(string username, string password)
        {
            var users = await _userRepository.GetAllAsync();

            var user = users.FirstOrDefault(x => x.UserName == username && x.Password == password);

            if (user != null)
            {
                _eventAggregator.GetEvent <LoginSuccessEvent>().Publish(user);
            }
            else
            {
                _messageDialogService.ShowInfoDialog("username or password is incorrect");
            }
        }
Пример #11
0
        private async void OnOpenDetailView(OpenDetailViewEventArgs args)
        {
            var detailViewModel = DetailViewModels
                                  .SingleOrDefault(vm => vm.Id == args.Id &&
                                                   vm.GetType().Name == args.ViewModelName);

            if (detailViewModel == null)
            {
                switch (args.ViewModelName)
                {
                case nameof(FriendDetailViewModel):
                    detailViewModel = _friendDetailViewModelCreator();
                    break;

                case nameof(MeetingDetailViewModel):
                    detailViewModel = _meetingDetailViewModelCreator();
                    break;

                case nameof(ProgrammingLanguageDetailViewModel):
                    detailViewModel = _programmingLanguageDetailViewModelCreator();
                    break;
                }

                // Verify item still exists (may have been deleted)

                try
                {
                    await detailViewModel.LoadAsync(args.Id);
                }
                catch
                {
                    _messageDialogService.ShowInfoDialog(
                        "Cannot load the entity, it may have been deleted" +
                        " by another user.  Updating Navigation");
                    await NavigationViewModel.LoadAsync();

                    return;
                }

                DetailViewModels.Add(detailViewModel);
            }

            SelectedDetailViewModel = detailViewModel;
        }
Пример #12
0
        protected override async void OnDeleteExecute()
        {
            if (await _repository.HasMeetingsAsync(Friend.Id))
            {
                _messageDialogService.ShowInfoDialog($"{Friend.FirstName} {Friend.LastName} can't be deleted");
                return;
            }
            var resultDialog =
                _messageDialogService.ShowOkCancelDialog(
                    $"Do you really want to delete frined {Friend.FirstName} {Friend.LastName}?", "Question");

            if (resultDialog == MessageDialogResult.OK)
            {
                _repository.Remove(Friend.Model);
                await _repository.SaveAsync();

                RaiseDetailDeletedEvent(Friend.Id);
            }
        }
        protected override async void OnDeleteExecute()
        {
            if (await _friendRepository.HasMeetingsAsync(Friend.Id))
            {
                _messageDialogService.ShowInfoDialog($"{Friend.FirstName} {Friend.LastName} can't be deleted, because it is appointed to one or more meetings.");
                return;
            }

            var result = _messageDialogService
                         .ShowOkCancelDialog($"Do you want do delete your friend {Friend.FirstName} {Friend.LastName}?", "Are you sure?");

            if (result == MessageDialogResult.Ok)
            {
                _friendRepository.Remove(Friend.Model);
                await _friendRepository.SaveAsync();

                RaiseDetailDeletedEvent(Friend.Id);
            }
        }
        protected override async void OnDeleteExecute()
        {
            //Check if friend is part of any meeting, if so don't delete and show messagebox
            if (await _friendRepository.HasMeetingsAsync(SelectedFriend.Id))
            {
                _messageDialogService.ShowInfoDialog($"{SelectedFriend.FirstName} {SelectedFriend.LastName} can't be deleted, as this friend is part of at least one meeting");
                return;
            }

            var result = _messageDialogService.ShowOkCancelDialog($"Do you really want to delete the friend {SelectedFriend.FirstName} {SelectedFriend.LastName}", "Question");

            if (result == MessageDialogResult.Ok)
            {
                _friendRepository.Remove(SelectedFriend.Model);
                await _friendRepository.SaveAsync();

                RaiseDetailDeletedEvent(SelectedFriend.Id);
            }
        }
Пример #15
0
        protected async Task SaveWithOptimisticConcurrencyAsync(Func <Task> saveFunc, Action afterSaveAction)
        {
            try
            {
                await saveFunc();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var databaseValues = ex.Entries.Single().GetDatabaseValues();

                if (databaseValues == null)
                {
                    MessageDialogService.ShowInfoDialog(
                        "The entity has been deleted by another user.  Cannot continue.");
                    RaiseDetailDeletedEvent(Id);
                    return;
                }

                var result = MessageDialogService.ShowOkCancelDialog(
                    "The entity has been changed by someone else." +
                    " Click OK to save your changes anyway; Click Cancel" +
                    " to reload the entity from the database.", "Question");

                if (result == MessageDialogResult.OK)   // Client Wins
                {
                    // Update the original values with database-values
                    var entry = ex.Entries.Single();
                    entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                    await saveFunc();
                }
                else  // Database Wins
                {
                    // Reload entity from database
                    await ex.Entries.Single().ReloadAsync();
                    await LoadAsync(Id);
                }
            }

            // Do anything that needs to occur after saving

            afterSaveAction();
        }
Пример #16
0
        private async void OnOpenDetailViewAsync(OpenDetailEventArgs args)
        {
            var detailViewModel = DetailViewModels.SingleOrDefault(vm => vm.Id == args.Id && vm.GetType().Name == args.ViewModelName);

            if (detailViewModel == null)
            {
                detailViewModel = _detailViewModelCreator[args.ViewModelName];
                try {
                    await detailViewModel.LoadAsync(args.Id);
                }
                catch
                {
                    _messageDialogService.ShowInfoDialog("Could not load the entity, maybe it's was delelted in the meantime by another user , the navigation will refresh.");
                    await NavigationViewModel.LoadAsync();

                    return;
                }
                DetailViewModels.Add(detailViewModel);
            }
            SelectedDetailViewModel = detailViewModel;
        }
        protected async Task SaveWithOptimisticConcurrencyAsnyc(Func <Task> saveFunc, Action afterSaveAction)
        {
            try
            {
                await saveFunc();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var databasevalue = ex.Entries.Single().GetDatabaseValues();
                if (databasevalue == null)
                {
                    await MessageDialogService.ShowInfoDialog("The entity has been deleted by another user");

                    RaiseDetailDeletedEvent(Id);
                    return;
                }

                var entityName = ex.Entries.Single().Entity.GetType().Name;
                var result     = await MessageDialogService.ShowOkCancelDialogAsync($"The entity, {entityName} has been changed by someone else. " +
                                                                                    "Click OK to save ur changes anyway, Click Cancel to realod the entity from the database.", "Question");

                // Update the original values in with the databse-values - Client Wins
                if (result == MessageDialogResult.Ok)
                {
                    var entry = ex.Entries.Single();
                    entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                    await saveFunc();
                }
                else
                {
                    // Reload entity from database - Database Wins
                    await ex.Entries.Single().ReloadAsync();
                    await LoadAsync(Id);
                }
            };

            afterSaveAction();
        }
Пример #18
0
        private void OnSaveCommand()
        {
            var oldfun = _functionDefinition.Function.getFunction(0);

            _functionDefinition.SetNewExpression(FunctionDefinedByUser); // have to check this one

            var result = _functionDefinition.Function.checkSyntax();

            if (result == false)
            {
                _messageDialogService.ShowInfoDialog("Nie poprawna składnia funkcji");
                _functionDefinition.SetNewExpression(oldfun);
                return;
            }
            _changedFunctionSyntax = false;
            ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged();

            if (IsArgumentChanged(oldfun))
            {
                UpdateVariablees();
            }
        }