示例#1
0
 private void BlockClient()
 {
     SelectedClient.IsBlocked = !SelectedClient.IsBlocked;
     SelectedClient.UserBlockedTextMessage = "";
     SelectedClient.UserToBlockButtonText  = "";
     ModelResourcesManager.GetInstance().UpdateModel(SelectedClient);
 }
示例#2
0
        private void DeclineCredit(IssuedCreditModel issuedCreditModel)
        {
            ModelResourcesManager.GetInstance().RemoveModel(issuedCreditModel);
            AwaitToApprovedCreditModels.Remove(issuedCreditModel);

            MessageBox.Show("Кредит отклонен");
        }
示例#3
0
        // Methods.
        private void LogIn()
        {
            try
            {
                var user = ModelResourcesManager.GetInstance().GetUserByLogin(Login) ??
                           throw new Exception("Пользователь с данным логином не найден.");
                if (user.Password != Password)
                {
                    throw new Exception("Неверно введён пароль.");
                }
                if (user.IsBlocked)
                {
                    throw new Exception("Пользователь заблокирован.");
                }

                // If login & password is typed correctly
                ModelResourcesManager.GetInstance().LoggedInUser = user;

                AuthorizationViewModel.ApplicationViewModel.GoToMainView();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
示例#4
0
        public AccountViewModel()
        {
            switch (MainViewModel.WindowFactory)
            {
            case ClientMainWindow:
                // Using data.
                AccountModels      = ModelResourcesManager.GetInstance().UserAccounts;
                CurrencyTypeModels = ModelResourcesManager.GetInstance().ExistedCurrencyTypes;
                CardTypeModels     = ModelResourcesManager.GetInstance().ExistedCardTypes;

                AccountToOpen = new AccountModel {
                    CurrencyTypeModelNavigation = CurrencyTypeModels[0]
                };
                CardToCreate = new CardModel {
                    CardTypeModelNavigation = CardTypeModels[0]
                };

                // Using VM
                ControlViewModels.Add(new AccountsListViewModel());
                ControlViewModels.Add(new CreateNewAccountViewModel());
                break;

            case AdminMainWindow:
            case WorkerMainWindow:

                // Using VM
                ControlViewModels.Add(new AccountsListViewModel());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SelectedControlViewModel = ControlViewModels.FirstOrDefault();
        }
        private void CreateNewCreditType()
        {
            ModelResourcesManager.GetInstance().AddModel(CreditTypeToCreate);
            ExistedCreditTypes.Add(CreditTypeToCreate);
            InitializeNewData();

            GoToCreditTypesList();
        }
        public TransferToAccountViewModel()
        {
            UserAccounts       = ModelResourcesManager.GetInstance().UserAccounts;
            UserJournal        = ModelResourcesManager.GetInstance().UserJournal;
            CurrencyTypeModels = ModelResourcesManager.GetInstance().ExistedCurrencyTypes;

            OperationCurrencyType = CurrencyTypeModels[0];
        }
示例#7
0
 public static MainWindowFactory GetFactory()
 {
     return(ModelResourcesManager.GetInstance().LoggedInUser.UserType switch
     {
         "admin" => new AdminMainWindow(),
         "worker" => new WorkerMainWindow(),
         "client" => new ClientMainWindow(),
         _ => null
     });
示例#8
0
        public ClientsViewModel()
        {
            ExistedClients = ModelResourcesManager.GetInstance().ExistedClients;

            ControlViewModels.Add(new ExistedClientsViewModel(this));
            ControlViewModels.Add(new SendClientNotificationViewModel(this));

            SelectedControlViewModel = ControlViewModels[0];
        }
示例#9
0
        public MainViewModel(ApplicationViewModel applicationViewModel)
        {
            ApplicationViewModel           = applicationViewModel;
            applicationViewModel.MinHeight = 500;
            applicationViewModel.MinWidth  = 700;

            WindowFactory = MainWindowFactory.GetFactory();
            ControlViewModels.AddRange(WindowFactory.GetPages());
            SelectedControlViewModel = ControlViewModels[0];

            ModelResourcesManager.GetInstance().CurrencyConverter.Attach(this);
        }
        public CreditsAdminPageViewModel()
        {
            ExistedCreditTypes = ModelResourcesManager.GetInstance().ExistedCreditTypes;

            ControlViewModels.Add(new CreditTypesListViewModel());
            ControlViewModels.Add(new CreateNewCreditTypeViewModel());
            ControlViewModels.Add(new UpdateExistedCreditTypeViewModel());

            SelectedControlViewModel = ControlViewModels.FirstOrDefault();

            CurrencyTypeModels = ModelResourcesManager.GetInstance().ExistedCurrencyTypes;

            InitializeNewData();
        }
示例#11
0
        private void CreateNewCredit()
        {
            CreditToTaking.UserId     = ModelResourcesManager.GetInstance().LoggedInUser.Id;
            CreditToTaking.DateIn     = DateTime.Now;
            CreditToTaking.IsApproved = false;
            CreditToTaking.IsRepaid   = false;
            CreditToTaking.AccountId  = AccountIdToPay.Id;

            ModelResourcesManager.GetInstance().AddModel(CreditToTaking);
            MessageBox.Show("Заявка оставлена");
            ResetCreditToTaking();

            SelectedControlViewModel = ControlViewModels[0];
        }
        private void DeleteCreditType()
        {
            var boxResult = MessageBox.Show("Вы действительно хотите удалить данный вид кредита?",
                                            "HarwexBank", MessageBoxButton.YesNo);

            if (boxResult != MessageBoxResult.Yes)
            {
                return;
            }

            ModelResourcesManager.GetInstance().RemoveModel(SelectedCreditType);
            ExistedCreditTypes.Remove(SelectedCreditType);

            GoToCreditTypesList();
        }
示例#13
0
        private void GenerateNotificationToClient()
        {
            JournalModel journalNote = new NotificationModel
            {
                UserId  = SelectedClient.Id,
                Date    = DateTime.Now,
                Message = NotificationMessage
            };

            ModelResourcesManager.GetInstance().GenerateJournalNote(journalNote);

            NotificationMessage = "";

            MessageBox.Show("Уведомление успешно отослано.");
        }
示例#14
0
        public JournalViewModel()
        {
            switch (MainViewModel.WindowFactory)
            {
            case ClientMainWindow:
                Journal = ModelResourcesManager.GetInstance().UserJournal;

                ControlViewModels.Add(new AllJournalNotesTabViewModel(this));
                ControlViewModels.Add(new TransfersTabViewModel(this));
                ControlViewModels.Add(new CreditRepaymentTabViewModel(this));
                ControlViewModels.Add(new NotificationTabViewModel(this));
                break;

            case AdminMainWindow:
            case WorkerMainWindow:
                Journal = ModelResourcesManager.GetInstance().AllJournal;

                ControlViewModels.Add(new AllJournalNotesTabViewModel(this));
                ControlViewModels.Add(new TransfersTabViewModel(this));
                ControlViewModels.Add(new CreditRepaymentTabViewModel(this));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Transfers        = new ObservableCollection <TransferToAccountModel>();
            CreditRepayments = new ObservableCollection <CreditRepaymentModel>();
            Notifications    = new ObservableCollection <NotificationModel>();

            foreach (var journalNote in Journal)
            {
                DetermineJournalModel(journalNote);
            }

            Journal.CollectionChanged += (_, e) =>
            {
                if (e.NewItems == null || e.Action != NotifyCollectionChangedAction.Add)
                {
                    return;
                }

                DetermineJournalModel((JournalModel)e.NewItems[0]);
            };

            SelectedControlViewModel = ControlViewModels[0];
        }
        // Methods.
        private void TransferToAccount()
        {
            if (AccountInitiator.IsFrozen)
            {
                MessageBox.Show("Счёт отправителя заморожен");
                return;
            }
            if (AccountReceiver.IsFrozen)
            {
                MessageBox.Show("Счёт получателя заморожен");
                return;
            }

            if (!AccountModel.CheckAccountAmountToPossibilityOfTransfer(
                    AccountInitiator.CurrencyTypeModelNavigation.CurrencyTypeEnum,
                    OperationCurrencyType.CurrencyTypeEnum,
                    AccountInitiator.Amount,
                    AmountToTransfer))
            {
                MessageBox.Show("Сумма не должна превышать сумму" +
                                $" счёта: {AccountInitiator.Amount} {AccountInitiator.CurrencyType}");
                return;
            }

            var currencyConverter = ModelResourcesManager.GetInstance().CurrencyConverter;

            AccountInitiator.Amount -= currencyConverter.ConvertCurrencies(
                AccountInitiator.CurrencyTypeModelNavigation.CurrencyTypeEnum,
                OperationCurrencyType.CurrencyTypeEnum, AmountToTransfer);
            AccountReceiver.Amount += currencyConverter.ConvertCurrencies(
                AccountReceiver.CurrencyTypeModelNavigation.CurrencyTypeEnum,
                OperationCurrencyType.CurrencyTypeEnum, AmountToTransfer);
            JournalModel journalNote = new TransferToAccountModel()
            {
                UserId = AccountInitiator.UserId,
                Date   = DateTime.Now,
                BankAccountInitiator        = AccountInitiator.Id,
                BankAccountReceiver         = AccountReceiver.Id,
                CurrencyTypeModelNavigation = OperationCurrencyType,
                Amount = AmountToTransfer
            };

            UserJournal.Add(journalNote);
            ModelResourcesManager.GetInstance().GenerateTransfer(journalNote, AccountInitiator, AccountReceiver);

            MessageBox.Show("Успешно переведено");
        }
示例#16
0
        // Methods.
        private void AcceptCredit(IssuedCreditModel issuedCreditModel)
        {
            issuedCreditModel.IsApproved = true;

            var currencyConverter = ModelResourcesManager.GetInstance().CurrencyConverter;
            var accountToPay      = ModelResourcesManager.GetInstance().GetAccountById(issuedCreditModel.AccountId);

            accountToPay.Amount += currencyConverter.ConvertCurrencies(
                accountToPay.CurrencyTypeModelNavigation.CurrencyTypeEnum,
                issuedCreditModel.CreditTypeModelNavigation.CurrencyTypeModelNavigation.CurrencyTypeEnum,
                issuedCreditModel.Amount);

            ModelResourcesManager.GetInstance().UpdateModel(issuedCreditModel);
            AwaitToApprovedCreditModels.Remove(issuedCreditModel);

            MessageBox.Show("Кредит принят");
        }
示例#17
0
        public CardsViewModel()
        {
            CardToCreate = new CardModel();

            LoggedInUser   = ModelResourcesManager.GetInstance().LoggedInUser;
            UserCards      = ModelResourcesManager.GetInstance().UserCards;
            UserAccounts   = ModelResourcesManager.GetInstance().UserAccounts;
            CardTypeModels = ModelResourcesManager.GetInstance().ExistedCardTypes;

            if (UserCards.Count > 0)
            {
                SelectedCard = UserCards[0];
            }

            ControlViewModels.Add(new CardsListViewModel());
            ControlViewModels.Add(new CreateNewCardViewModel());

            SelectedControlViewModel = ControlViewModels[0];
        }
        public string this[string name]
        {
            get
            {
                if (AccountInitiator is null)
                {
                    return("Выберите сначала счёт");
                }

                switch (name)
                {
                case nameof(AccountReceiverId):
                    if ((AccountReceiver = ModelResourcesManager.GetInstance().GetAccountById(AccountReceiverId)) == null)
                    {
                        return("Введённый счёт не найден");
                    }
                    if (AccountReceiver == AccountInitiator)
                    {
                        return("Введённые счёта не должны совпадать");
                    }
                    break;

                case nameof(AmountToTransfer):
                    if (AmountToTransfer <= 0)
                    {
                        return("Сумма не должна быть меньше, либо равна нулю");
                    }
                    if (!AccountModel.CheckAccountAmountToPossibilityOfTransfer(
                            AccountInitiator.CurrencyTypeModelNavigation.CurrencyTypeEnum,
                            OperationCurrencyType.CurrencyTypeEnum,
                            AccountInitiator.Amount,
                            AmountToTransfer))
                    {
                        return($"Сумма не должна превышать сумму счёта: {AccountInitiator.Amount} {AccountInitiator.CurrencyType}");
                    }
                    break;
                }

                return(null);
            }
        }
示例#19
0
        private void CreateAccountModel()
        {
            // Adding Account Model to DB.
            AccountToOpen.UserId           = ModelResourcesManager.GetInstance().LoggedInUser.Id;
            AccountToOpen.RegistrationDate = DateTime.Now;
            AccountToOpen.Amount           = 0;
            AccountToOpen.IsFrozen         = false;
            ModelResourcesManager.GetInstance().AddModel(AccountToOpen);

            // Adding Card Model to DB.
            var number = string.Empty;

            for (var i = 0; i < 16; i++)
            {
                number += new Random().Next(0, 9).ToString();
            }
            CardToCreate.AccountId = AccountToOpen.Id;
            CardToCreate.Number    = number;
            CardToCreate.OwnerName = ModelResourcesManager.GetInstance().LoggedInUser.FirstName.ToUpper() + " " +
                                     ModelResourcesManager.GetInstance().LoggedInUser.LastName.ToUpper();
            CardToCreate.TimeFrame = new Random().Next(0, 12) + "/" + (DateTime.Now.Year + 3).ToString()[2..];
示例#20
0
        public CreditViewModel()
        {
            switch (MainViewModel.WindowFactory)
            {
            case ClientMainWindow:
                // Using data.
                UserApprovedCreditModels = ModelResourcesManager.GetInstance().UserCredits;
                UserAccounts             = ModelResourcesManager.GetInstance().UserAccounts;
                CreditTypeModels         = ModelResourcesManager.GetInstance().ExistedCreditTypes;

                ResetCreditToTaking();

                // Using VM
                ControlViewModels.Add(new CreditListViewModel());
                ControlViewModels.Add(new TakeNewCreditViewModel());
                break;

            case WorkerMainWindow:

                // Using VM
                ControlViewModels.Add(new CreditListViewModel());
                break;

            case AdminMainWindow:
                // Using VM
                ControlViewModels.Add(new CreditListViewModel());

                CreditTypeModels = ModelResourcesManager.GetInstance().ExistedCreditTypes;

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            SelectedControlViewModel = ControlViewModels.FirstOrDefault();
        }
        private void SaveUpdatesOfCreditType()
        {
            ModelResourcesManager.GetInstance().UpdateModel(SelectedCreditType);

            MessageBox.Show("Изменения успешно применены");
        }
示例#22
0
        private void FinishRegistration()
        {
            ModelResourcesManager.GetInstance().AddModel(RegisteredUser);

            AuthorizationViewModel.RegistrationFinished();
        }
示例#23
0
 public CreditsWorkerPageViewModel()
 {
     AwaitToApprovedCreditModels = ModelResourcesManager.GetInstance().AllNonApprovedCredits;
 }