Exemplo n.º 1
0
        public async Task <IEnumerable <OrphanageDataModel.FinancialData.Account> > GetAccounts(int pageSize, int pageNum)
        {
            IList <OrphanageDataModel.FinancialData.Account> accountsList = new List <OrphanageDataModel.FinancialData.Account>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                int totalSkiped   = pageSize * pageNum;
                int accountsCount = await _orphanageDBC.Bails.AsNoTracking().CountAsync();

                if (accountsCount < totalSkiped)
                {
                    totalSkiped = accountsCount - pageSize;
                }
                if (totalSkiped < 0)
                {
                    totalSkiped = 0;
                }
                var accounts = await _orphanageDBC.Accounts.AsNoTracking()
                               .OrderBy(c => c.Id).Skip(() => totalSkiped).Take(() => pageSize)
                               .Include(a => a.Bails)
                               .Include(b => b.Guarantors)
                               .ToListAsync();

                foreach (var account in accounts)
                {
                    OrphanageDataModel.FinancialData.Account accountToFill = account;
                    _selfLoopBlocking.BlockAccountSelfLoop(ref accountToFill);
                    accountsList.Add(accountToFill);
                }
            }
            return(accountsList);
        }
        public async Task <OrphanageDataModel.FinancialData.Account> getAccount(int Aid)
        {
            var returnedAccount = await _apiClient.Accounts_GetAsync(Aid);

            _CurrentAccount = returnedAccount;
            return(returnedAccount);
        }
Exemplo n.º 3
0
 private async void btnSave_Click(object sender, EventArgs e)
 {
     _accountEntityValidator.controlCollection = Controls;
     _accountEntityValidator.DataEntity        = accountBindingSource.DataSource;
     if (_accountEntityValidator.IsValid())
     {
         _account = (OrphanageDataModel.FinancialData.Account)accountBindingSource.DataSource;
         if (_AccountId == -1)
         {
             if (await _accountEditViewModel.Add(_account) != null)
             {
                 this.DialogResult = DialogResult.OK;
                 this.Close();
             }
         }
         else
         {
             if (await _accountEditViewModel.Save(_account))
             {
                 this.DialogResult = DialogResult.OK;
                 this.Close();
             }
         }
     }
     else
     {
         ValidateAndShowError();
     }
 }
Exemplo n.º 4
0
        public void BlockAccountSelfLoop(ref OrphanageDataModel.FinancialData.Account account)
        {
            if (account == null)
            {
                return;
            }

            if (account.Bails != null)
            {
                foreach (var bail in account.Bails)
                {
                    if (bail.Account != null)
                    {
                        bail.Account = null;
                    }
                }
            }

            if (account.Guarantors != null)
            {
                foreach (var guarantor in account.Guarantors)
                {
                    if (guarantor.Account != null)
                    {
                        guarantor.Account = null;
                    }
                }
            }
        }
        public async Task <bool> Save(OrphanageDataModel.FinancialData.Account account)
        {
            try
            {
                await _apiClient.Accounts_PutAsync(account);

                return(true);
            }
            catch (ApiClientException apiEx)
            {
                return(_exceptionHandler.HandleApiSaveException(apiEx));
            }
        }
        public async Task <OrphanageDataModel.FinancialData.Account> Add(OrphanageDataModel.FinancialData.Account account)
        {
            try
            {
                account.UserId = Program.CurrentUser.Id;
                var retBail = (OrphanageDataModel.FinancialData.Account) await _apiClient.Accounts_PostAsync(account);
            }
            catch (ApiClientException apiEx)
            {
                return(await _exceptionHandler.HandleApiPostFunctions(getAccount, apiEx));
            }

            return(null);
        }
Exemplo n.º 7
0
        public async Task <HttpResponseMessage> Post(object account)
        {
            var accountEntity = JsonConvert.DeserializeObject <OrphanageDataModel.FinancialData.Account>(account.ToString());

            OrphanageDataModel.FinancialData.Account ret = null;

            ret = await _accountDbService.AddAccount(accountEntity);

            if (ret != null)
            {
                return(Request.CreateResponse(System.Net.HttpStatusCode.Created, ret));
            }
            else
            {
                return(_httpMessageConfiguerer.NothingChanged());
            }
        }
Exemplo n.º 8
0
        public async Task <bool> SaveAccount(OrphanageDataModel.FinancialData.Account accountToSave)
        {
            _logger.Information($"Trying to save Account");
            if (accountToSave == null)
            {
                _logger.Error($"the parameter object accountToSave is null, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            using (OrphanageDbCNoBinary orphanageDc = new OrphanageDbCNoBinary())
            {
                int ret = 0;
                orphanageDc.Configuration.LazyLoadingEnabled       = true;
                orphanageDc.Configuration.ProxyCreationEnabled     = true;
                orphanageDc.Configuration.AutoDetectChangesEnabled = true;

                var orginalAccount = await orphanageDc.Accounts.
                                     FirstOrDefaultAsync(m => m.Id == accountToSave.Id);

                if (orginalAccount == null)
                {
                    _logger.Error($"the original account object with id {accountToSave.Id} object is not founded, ObjectNotFoundException will be thrown");
                    throw new Exceptions.ObjectNotFoundException();
                }

                orginalAccount.AccountName      = accountToSave.AccountName;
                orginalAccount.Amount           = accountToSave.Amount;
                orginalAccount.CanNotBeNegative = accountToSave.CanNotBeNegative;
                orginalAccount.Currency         = accountToSave.Currency;
                orginalAccount.CurrencyShortcut = accountToSave.CurrencyShortcut;
                orginalAccount.Note             = accountToSave.Note;
                ret += await orphanageDc.SaveChangesAsync();

                if (ret > 0)
                {
                    _logger.Information($"the object account with id {orginalAccount.Id} has been saved successfully, {ret} changes has been made ");
                    return(true);
                }
                else
                {
                    _logger.Information($"the object account with id {orginalAccount.Id} has been saved successfully, nothing has changed");
                    return(false);
                }
            }
        }
Exemplo n.º 9
0
 private void btnChooseAccount_Click(object sender, EventArgs e)
 {
     ChooserView.ChooserView chooserView = new ChooserView.ChooserView(new List <object>(_guarantorEditViewModel.Accounts), Properties.Resources.ChooseAccount);
     chooserView.MultiSelect = false;
     chooserView.ShowDialog();
     if (chooserView.DialogResult == DialogResult.OK)
     {
         var accountModel = (AccountModel)chooserView.SelectedObject;
         _account = _guarantorEditViewModel.GetSourceAccount(accountModel.Id);
         ((OrphanageDataModel.Persons.Guarantor)(guarantorBindingSource.DataSource)).AccountId = _account.Id;
         ((OrphanageDataModel.Persons.Guarantor)(guarantorBindingSource.DataSource)).Account   = _account;
         EnableDisableControls(true);
         txtAccountName.Text = accountModel.AccountName;
     }
     else
     {
         EnableDisableControls(false);
     }
 }
Exemplo n.º 10
0
        public async Task <IEnumerable <OrphanageDataModel.FinancialData.Account> > GetAccounts(IEnumerable <int> accoutnsIds)
        {
            IList <OrphanageDataModel.FinancialData.Account> accountsList = new List <OrphanageDataModel.FinancialData.Account>();

            using (var _orphanageDBC = new OrphanageDbCNoBinary())
            {
                var accounts = await _orphanageDBC.Accounts.AsNoTracking()
                               .Where(a => accoutnsIds.Contains(a.Id))
                               .Include(a => a.Bails)
                               .Include(b => b.Guarantors)
                               .ToListAsync();

                foreach (var account in accounts)
                {
                    OrphanageDataModel.FinancialData.Account accountToFill = account;
                    _selfLoopBlocking.BlockAccountSelfLoop(ref accountToFill);
                    accountsList.Add(accountToFill);
                }
            }
            return(accountsList);
        }
Exemplo n.º 11
0
        private async void AccountEditView_Load(object sender, EventArgs e)
        {
            if (_AccountId != -1)
            {
                _account = await _accountEditViewModel.getAccount(_AccountId);

                if (_account != null)
                {
                    accountBindingSource.DataSource = _account;
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }
            }
            else
            {
                accountBindingSource.DataSource = new OrphanageDataModel.FinancialData.Account();
            }
        }
Exemplo n.º 12
0
        private void SetData()
        {
            guarantorBindingSource.DataSource = _Guarantor;
            clrColor.Value           = _Guarantor.ColorMark.HasValue ? Color.FromArgb((int)_Guarantor.ColorMark.Value) : Color.Black;
            _account                 = _Guarantor.Account;
            nameForm1.NameDataSource = _Guarantor.Name;
            if (_Guarantor.Address != null)
            {
                addressForm1.AddressDataSource = _Guarantor.Address;
            }
            else
            {
                addressForm1.AddressDataSource = new Address();
            }

            txtAccountName.Text = _account.AccountName;
            txtName.Text        = nameForm1.FullName;
            txtAddress.Text     = addressForm1.FullAddress;
            _GuarantorEntityValidator.controlCollection = Controls;
            _GuarantorEntityValidator.DataEntity        = _Guarantor;
        }
Exemplo n.º 13
0
        public async Task <OrphanageDataModel.FinancialData.Account> AddAccount(OrphanageDataModel.FinancialData.Account accountToAdd)
        {
            _logger.Information($"Trying to add new Account");
            if (accountToAdd == null)
            {
                _logger.Error($"the parameter object accountToAdd is null, NullReferenceException will be thrown");
                throw new NullReferenceException();
            }
            using (var orphanageDBC = new OrphanageDbCNoBinary())
            {
                using (var Dbt = orphanageDBC.Database.BeginTransaction())
                {
                    if (accountToAdd.ActingUser != null)
                    {
                        accountToAdd.ActingUser = null;
                    }
                    orphanageDBC.Accounts.Add(accountToAdd);
                    var ret = await orphanageDBC.SaveChangesAsync();

                    if (ret >= 1)
                    {
                        Dbt.Commit();
                        _logger.Information($"new Account object with id{accountToAdd.Id} has been added");
                        _selfLoopBlocking.BlockAccountSelfLoop(ref accountToAdd);
                        _logger.Information($"the Account object with id{accountToAdd.Id} will be returned");
                        return(accountToAdd);
                    }
                    else
                    {
                        Dbt.Rollback();
                        _logger.Information($"something went wrong, nothing was added, null will be returned");
                        return(null);
                    }
                }
            }
        }