Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 private void FixBalanceForCreatedAccount(OrgAccountViewModel account)
 {
     _fixingBalanceService.AddNewBalance(new BalanceViewModel
     {
         Amount       = account.CurrentBalance,
         BalanceDate  = account.CreationDate,
         OrgAccountId = account.Id
     });
 }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
 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);
     }
 }
Ejemplo n.º 7
0
 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);
     }
 }
Ejemplo n.º 8
0
 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);
     }
 }
Ejemplo n.º 9
0
 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("Неможливо створити рахунок невизначеного типу");
     }
 }
Ejemplo n.º 10
0
 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);
     }
 }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
 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);
 }
Ejemplo n.º 13
0
 public JsonResult Edit([FromBody] OrgAccountViewModel model)
 {
     return(Json(this._orgAccountService.UpdateOrganizationAccount(model)));
 }
Ejemplo n.º 14
0
        public JsonResult Create([FromBody] OrgAccountViewModel model)
        {
            var item = this._orgAccountService.CreateOrganizationAccount(model);

            return(Json(item));
        }
Ejemplo n.º 15
0
 public OrgAccountViewModel UpdateOrganizationAccount([FromBody] OrgAccountViewModel account)
 {
     return(_orgAccountService.UpdateOrganizationAccount(account));
 }
Ejemplo n.º 16
0
        public IActionResult Create([FromBody] OrgAccountViewModel model)
        {
            var item = _orgAccountService.CreateOrganizationAccount(model);

            return(Ok(item));
        }
Ejemplo n.º 17
0
 public IActionResult Edit([FromBody] OrgAccountViewModel model)
 {
     return(Ok(_orgAccountService.UpdateOrganizationAccount(model)));
 }