public OrgAccountViewModel InitializeOrgAccountViewModel(OrgAccount item) { var account = new OrgAccountViewModel(); switch (item.AccountType) { case "Готівка": account = this.InitializeCommonProperties(item); account.AccountType = "Готівка"; break; case "Банк": account = this.InitializeCommonProperties(item); account.AccountType = "Банк"; account.BankName = item.BankAccount.BankName; account.AccNumber = item.BankAccount.AccNumber; account.EDRPOU = item.BankAccount.EDRPOU; account.MFO = item.BankAccount.MFO; account.Description = item.Description; account.CardNumber = item.BankAccount.CardNumber; account.BankAccId = item.BankAccId; break; default: break; } return(account); }
public OrgAccountViewModel CreateCashAccount(OrgAccountViewModel model) { var account = new OrgAccount(); try { var message = this.ValidateOrgAccount(model); if (message != String.Empty) { return(new OrgAccountViewModel { Error = message }); } account.AccountType = "Готівка"; Int32.TryParse(model.Currency, out var currencyId); account.Currency = this._unitOfWork.CurrencyRepositry.Get(currencyId); account.CurrentBalance = model.CurrentBalance; account.OrgAccountName = model.OrgAccountName; account.Organization = this._unitOfWork.OrganizationRepository.Get(model.OrgId); account.TargetId = model.TargetId; this._unitOfWork.OrganizationAccountRepository.Create(account); this._unitOfWork.SaveChanges(); return((OrgAccountViewModel)account); } catch (Exception e) { string message = string.Format("Неможливо створити рахунок організації. Помилка: {0}", e.Message); throw new BusinessLogicException(message, e); } }
public OrgAccountViewModel CreateCashAccount(OrgAccountViewModel model) { var account = new OrgAccount(); try { var message = this.ValidateOrgAccount(model); if (message != String.Empty) { return(new OrgAccountViewModel { Error = message }); } account.AccountType = "Готівка"; Int32.TryParse(model.Currency, out var currencyId); account.Currency = this._unitOfWork.CurrencyRepositry.Get(currencyId); account.CurrentBalance = model.CurrentBalance; account.OrgAccountName = model.OrgAccountName; account.Organization = this._unitOfWork.OrganizationRepository.Get(model.OrgId); account.TargetId = model.TargetId; account.Description = model.Description; account.UserId = model.UserId; account.CreationDate = model.CreationDate; this._unitOfWork.OrganizationAccountRepository.Create(account); this._unitOfWork.SaveChanges(); return((OrgAccountViewModel)account); } catch (Exception e) { throw new BusinessLogicException(ErrorMessages.CantCreateAccountOfOrganization, e); } }
private void FixBalanceForCreatedAccount(OrgAccountViewModel account) { _fixingBalanceService.AddNewBalance(new BalanceViewModel { Amount = account.CurrentBalance, BalanceDate = account.CreationDate, OrgAccountId = account.Id }); }
public OrgAccountViewModel UpdateOrganizationAccount(OrgAccountViewModel model) { try { var result = _unitOfWork.OrganizationAccountRepository.Edit(model); _unitOfWork.SaveChanges(); return(result); } catch (Exception e) { string message = string.Format("Неможливо оновити рахунок організації. Помилка: {0}", e.Message); throw new BusinessLogicException(message, e); } }
public OrgAccountViewModel GetOrganizationAccountById(int organizationAccountId) { try { var account = this._unitOfWork.OrganizationAccountRepository.Read(organizationAccountId); OrgAccountViewModel model = this.InitializeOrgAccountViewModel(account); return(model); } catch (Exception e) { string message = string.Format("Неможливо отримати рахунок організації. Помилка: {0}", e.Message); throw new BusinessLogicException(message, e); } }
public OrgAccountViewModel UpdateOrganizationAccount(OrgAccountViewModel model) { try { var result = _unitOfWork.OrganizationAccountRepository.GetOrgAccountById(model.Id); result.UserId = model.UserId; result.TargetId = model.TargetId; _unitOfWork.OrganizationAccountRepository.Edit(result); _unitOfWork.SaveChanges(); return(result); } catch (Exception e) { throw new BusinessLogicException(ErrorMessages.UpdateOrganizationAccount, e); } }
public OrgAccountViewModel GetOrganizationAccountById(int accountId) { try { var account = this._unitOfWork.OrganizationAccountRepository.Read(accountId); if (account == null) { return(new OrgAccountViewModel()); } OrgAccountViewModel model = this.InitializeOrgAccountViewModel(account); return(model); } catch (Exception e) { throw new BusinessLogicException(ErrorMessages.GetOrganizationAccount, e); } }
public OrgAccountViewModel CreateOrganizationAccount(OrgAccountViewModel model) { if (model.AccountType == "cash") { var item = this.CreateCashAccount(model); return(item); } else if (model.AccountType == "bank") { var item = this.CreateBankAccount(model); return(item); } else { throw new BusinessLogicException("Неможливо створити рахунок невизначеного типу"); } }
public OrgAccountViewModel CreateOrganizationAccount(OrgAccountViewModel model) { if (model.AccountType == "cash") { var item = this.CreateCashAccount(model); FixBalanceForCreatedAccount(item); return(item); } else if (model.AccountType == "bank") { var item = this.CreateBankAccount(model); FixBalanceForCreatedAccount(item); return(item); } else { throw new BusinessLogicException(ErrorMessages.CantCreateAccountWithundefinedType); } }
public string ValidateOrgAccount(OrgAccountViewModel model) { ///Checks if account with such name already exists within organization foreach (var item in this._unitOfWork.OrganizationAccountRepository.ReadAllOrgAccounts(model.OrgId)) { if (item.OrgAccountName == model.OrgAccountName) { return("Рахунок організації з таким іменем уже існує"); } } if (model.AccountType == "bank") { ///Checks if account with such bank number already exists within all organizations foreach (var item in this._unitOfWork.OrganizationAccountRepository.GetAllOrgAccounts().Where(a => a.AccountType == "Банк")) { if (item.BankAccount.AccNumber == model.AccNumber) { return("Рахунок з таким номером уже зареєстрований"); } } } return(String.Empty); }
public string ValidateOrgAccount(OrgAccountViewModel model) { //Checks if account with such name already exists within organization foreach (var item in this._unitOfWork.OrganizationAccountRepository.ReadAllOrgAccounts(model.OrgId)) { if (item.OrgAccountName == model.OrgAccountName) { return(ErrorMessages.OrganizarionAccountWithNameExists); } } if (model.AccountType == "bank") { //Checks if account with such bank number already exists within all organizations foreach (var item in this._unitOfWork.OrganizationAccountRepository.GetAllOrgAccounts().Where(a => a.AccountType == "Банк")) { if (item.BankAccount.AccNumber != null && item.BankAccount.AccNumber == model.AccNumber) { return(ErrorMessages.OrganizarionAccountWithNumberExists); } } } return(String.Empty); }
public JsonResult Edit([FromBody] OrgAccountViewModel model) { return(Json(this._orgAccountService.UpdateOrganizationAccount(model))); }
public JsonResult Create([FromBody] OrgAccountViewModel model) { var item = this._orgAccountService.CreateOrganizationAccount(model); return(Json(item)); }
public OrgAccountViewModel UpdateOrganizationAccount([FromBody] OrgAccountViewModel account) { return(_orgAccountService.UpdateOrganizationAccount(account)); }
public IActionResult Create([FromBody] OrgAccountViewModel model) { var item = _orgAccountService.CreateOrganizationAccount(model); return(Ok(item)); }
public IActionResult Edit([FromBody] OrgAccountViewModel model) { return(Ok(_orgAccountService.UpdateOrganizationAccount(model))); }