Esempio n. 1
0
        /// <summary>
        /// Creates the fin op.
        /// </summary>
        /// <param name="finOpModel">The fin op model.</param>
        /// <returns></returns>
        public FinOpFromBankViewModel CreateFinOp(FinOpFromBankViewModel finOpModel)
        {
            try
            {
                var finOp = new FinOp
                {
                    AccFromId   = _unitOfWork.OrganizationAccountRepository.GetOrgAccountByName(finOpModel.OrgId, finOpModel.AccFromName).Id,
                    AccToId     = _unitOfWork.OrganizationAccountRepository.GetOrgAccountByName(finOpModel.OrgId, finOpModel.AccToName).Id,
                    TargetId    = _unitOfWork.TargetRepository.GetTargetByName(finOpModel.TargetName).Id,
                    Amount      = finOpModel.Amount,
                    Description = finOpModel.Description,
                    FinOpDate   = DateTime.Now
                };

                var finOpEntity = _unitOfWork.FinOpRepository.Create(finOp);
                _unitOfWork.SaveChanges();

                var createdFinOp = _unitOfWork.FinOpRepository.GetById(finOpEntity.Id);
                createdFinOp.OrgAccountTo.CurrentBalance += finOpModel.Amount;
                _unitOfWork.FinOpRepository.Update(createdFinOp);

                var bankImportDetail = _unitOfWork.BankImportDetailRepository.GetById(finOpModel.BankImportId);
                bankImportDetail.IsLooked = true;
                _unitOfWork.BankImportDetailRepository.ChangeBankImportState(bankImportDetail);

                _unitOfWork.SaveChanges();
                return(finOpModel);
            }
            catch (Exception ex)
            {
                throw new BusinessLogicException(ex.Message, ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the specified fin op.
        /// </summary>
        /// <param name="finOp">The fin op.</param>
        /// <returns></returns>
        public FinOp Update(FinOp finOp)
        {
            //_context.Entry(finOp).State = EntityState.Modified;
            var updatedFinOp = this._context.FinOps.Update(finOp);

            return(updatedFinOp.Entity);
        }
Esempio n. 3
0
 public FinOpViewModel CreateIncome(FinOpViewModel finOpModel)
 {
     FinOpInputDataValidation(finOpModel);
     try
     {
         var orgAcc = _unitOfWork.OrganizationAccountRepository.GetOrgAccountByName(finOpModel.OrgId, finOpModel.CardTo);
         var finOp  = new FinOp
         {
             Amount      = finOpModel.Sum,
             AccToId     = orgAcc.Id,
             Description = finOpModel.Description,
             TargetId    = finOpModel.TargetId,
             FinOpDate   = DateTime.Now,
         };
         _unitOfWork.FinOpRepository.Create(finOp);
         orgAcc.CurrentBalance += finOpModel.Sum;
         _unitOfWork.OrganizationAccountRepository.Edit(orgAcc);
         _unitOfWork.SaveChanges();
         return(finOpModel);
     }
     catch (Exception ex)
     {
         throw new BusinessLogicException("Щось пішло не так....О_о", ex);
     }
 }
Esempio n. 4
0
 public FinOpViewModel CreateTransfer(FinOpViewModel finOpModel)
 {
     FinOpInputDataValidation(finOpModel);
     try
     {
         var orgAccFrom = _unitOfWork.OrganizationAccountRepository.GetOrgAccountById(finOpModel.AccFromId);
         var orgAccTo   = _unitOfWork.OrganizationAccountRepository.GetOrgAccountById(finOpModel.AccToId);
         if (finOpModel.Amount > orgAccFrom.CurrentBalance)
         {
             throw new ArgumentException(ErrorMessages.SpendingIsExceeded);
         }
         var finOp = new FinOp
         {
             Amount      = finOpModel.Amount,
             AccToId     = orgAccTo.Id,
             AccFromId   = orgAccFrom.Id,
             Description = finOpModel.Description,
             FinOpDate   = finOpModel.Date,
             FinOpType   = finOpModel.FinOpType,
             UserId      = finOpModel.UserId
         };
         _unitOfWork.FinOpRepository.Create(finOp);
         orgAccFrom.CurrentBalance -= finOpModel.Amount;
         _unitOfWork.OrganizationAccountRepository.Edit(orgAccFrom);
         orgAccTo.CurrentBalance += finOpModel.Amount;
         _unitOfWork.OrganizationAccountRepository.Edit(orgAccTo);
         _unitOfWork.SaveChanges();
         return(finOpModel);
     }
     catch (Exception ex)
     {
         throw new BusinessLogicException(ErrorMessages.OperationTransferError, ex);
     }
 }
Esempio n. 5
0
 public FinOpViewModel CreateTransfer(FinOpViewModel finOpModel)
 {
     FinOpInputDataValidation(finOpModel);
     try
     {
         var orgAccFrom = _unitOfWork.OrganizationAccountRepository.GetOrgAccountByName(finOpModel.OrgId, finOpModel.CardFrom);
         var orgAccTo   = _unitOfWork.OrganizationAccountRepository.GetOrgAccountByName(finOpModel.OrgId, finOpModel.CardTo);
         if (finOpModel.Sum > orgAccFrom.CurrentBalance)
         {
             throw new ArgumentException("Витрати не можуть перебільшувати баланс рахунку");
         }
         var finOp = new FinOp
         {
             Amount      = finOpModel.Sum,
             AccToId     = orgAccTo.Id,
             AccFromId   = orgAccFrom.Id,
             Description = finOpModel.Description,
             FinOpDate   = DateTime.Now,
         };
         _unitOfWork.FinOpRepository.Create(finOp);
         orgAccFrom.CurrentBalance -= finOpModel.Sum;
         _unitOfWork.OrganizationAccountRepository.Edit(orgAccFrom);
         orgAccTo.CurrentBalance += finOpModel.Sum;
         _unitOfWork.OrganizationAccountRepository.Edit(orgAccTo);
         _unitOfWork.SaveChanges();
         return(finOpModel);
     }
     catch (Exception ex)
     {
         throw new BusinessLogicException("Щось пішло не так....О_о", ex);
     }
 }
Esempio n. 6
0
 ///
 public FinOpViewModel CreateIncome(FinOpViewModel finOpModel)
 {
     FinOpInputDataValidation(finOpModel);
     try
     {
         var orgAccTo = _unitOfWork.OrganizationAccountRepository.GetOrgAccountById(finOpModel.AccToId);
         var finOp    = new FinOp
         {
             Amount      = finOpModel.Amount,
             AccToId     = orgAccTo.Id,
             Description = finOpModel.Description,
             TargetId    = finOpModel.TargetId,
             FinOpDate   = finOpModel.Date,
             FinOpType   = finOpModel.FinOpType,
             UserId      = finOpModel.UserId
         };
         _unitOfWork.FinOpRepository.Create(finOp);
         orgAccTo.CurrentBalance += finOpModel.Amount;
         _unitOfWork.OrganizationAccountRepository.Edit(orgAccTo);
         _unitOfWork.SaveChanges();
         return(finOpModel);
     }
     catch (Exception ex)
     {
         throw new BusinessLogicException(ErrorMessages.OperationIncomeError, ex);
     }
 }
Esempio n. 7
0
        public void Deposite(FinOpViewModel finOpModel, FinOp finOp)
        {
            var orgAccFrom = _unitOfWork.OrganizationAccountRepository.GetOrgAccountById(finOpModel.AccFromId);

            orgAccFrom.CurrentBalance -= finOpModel.Amount;
            finOp.FinOpType            = finOpModel.FinOpType;
            finOp.AccToId              = finOpModel.AccToId;
            _unitOfWork.OrganizationAccountRepository.Edit(orgAccFrom);
        }
Esempio n. 8
0
        public void Windtrhaw(FinOpViewModel finOpModel, FinOp finOp)
        {
            var orgAccTo = _unitOfWork.OrganizationAccountRepository.GetOrgAccountById(finOpModel.AccToId);

            orgAccTo.CurrentBalance += finOpModel.Amount;
            finOp.FinOpType          = finOpModel.FinOpType;
            finOp.AccToId            = finOpModel.AccToId;
            _unitOfWork.OrganizationAccountRepository.Edit(orgAccTo);
        }
Esempio n. 9
0
 public static FinOpViewModel ConvertFinOpToViewModel(FinOp f)
 {
     return(new FinOpViewModel
     {
         Id = f.Id,
         Description = f.Description,
         Amount = f.Amount,
         AccToId = f.AccToId ?? 0,
         AccFromId = f.AccFromId ?? 0,
         OrgId = f.OrgAccountTo?.OrgId ?? f.OrgAccountFrom.OrgId,
         Target = f.Target?.TargetName,
         TargetId = f.TargetId,
         UserId = f.UserId ?? 0,
         FinOpType = f.FinOpType,
         Date = f.FinOpDate,
         DonationId = f.DonationId
     });
 }
Esempio n. 10
0
 /// <summary>
 /// Configures model creation
 /// </summary>
 /// <param name="modelBuilder">modelBuilder to configure Model Creation</param>
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     User.Configure(modelBuilder);
     Phone.Configure(modelBuilder);
     Address.Configure(modelBuilder);
     UserAddress.Configure(modelBuilder);
     Role.Configure(modelBuilder);
     Organization.Configure(modelBuilder);
     OrgAddress.Configure(modelBuilder);
     ExternalContact.Configure(modelBuilder);
     Membership.Configure(modelBuilder);
     Currency.Configure(modelBuilder);
     BankAccount.Configure(modelBuilder);
     OrgAccount.Configure(modelBuilder);
     Balance.Configure(modelBuilder);
     Target.Configure(modelBuilder);
     FinOp.Configure(modelBuilder);
     Tag.Configure(modelBuilder);
     TagFinOp.Configure(modelBuilder);
     Event.Configure(modelBuilder);
     EventImage.Configure(modelBuilder);
     Complaint.Configure(modelBuilder);
     GoodsType.Configure(modelBuilder);
     GoodsCategory.Configure(modelBuilder);
     OfferedItem.Configure(modelBuilder);
     RequestedItem.Configure(modelBuilder);
     BankImport.Configure(modelBuilder);
     BankImportDetail.Configure(modelBuilder);
     PasswordReset.Configure(modelBuilder);
     BannedUser.Configure(modelBuilder);
     BannedOrganization.Configure(modelBuilder);
     SubscribeOrganization.Configure(modelBuilder);
     Status.Configure(modelBuilder);
     OfferedItemImage.Configure(modelBuilder);
     RequestedItemImage.Configure(modelBuilder);
     UserResponse.Configure(modelBuilder);
     OrganizationResponse.Configure(modelBuilder);
     Donation.Configure(modelBuilder);
     Bank.Configure(modelBuilder);
     AutoImportIntervals.Configure(modelBuilder);
 }
Esempio n. 11
0
        /// <summary>
        /// Creates the specified fin op.
        /// </summary>
        /// <param name="finOp">The fin op.</param>
        /// <returns></returns>
        public FinOp Create(FinOp finOp)
        {
            var createdFinOp = this._context.FinOps.Add(finOp);

            return(createdFinOp.Entity);
        }