예제 #1
0
        public CompanyDto Insert(CompanyInsertDto dto)
        {
            CompanyDto companyDto = null;

            try
            {
                var company = Mapper.Map <CompanyInsertDto, Company>(dto);
                company.CreatedBy = _appSession.GetUserName();
                company.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <Company>().Insert(company);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                companyDto = Mapper.Map <Company, CompanyDto>(company);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(companyDto);
        }
        public BranchCommissionDto Insert(BranchCommissionInsertDto dto)
        {
            BranchCommissionDto branchCommissionDto = null;

            try
            {
                var branchCommission = Mapper.Map <BranchCommissionInsertDto, BranchCommission>(dto);
                branchCommission.CreatedBy = _appSession.GetUserName();
                branchCommission.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                var branch = _unitOfWork.GenericRepository <Domain.Model.Branches.Branch>().GetAll().FirstOrDefault();
                branchCommission.BranchId = branch.Id;

                _unitOfWork.GenericRepository <BranchCommission>().Insert(branchCommission);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                branchCommissionDto = Mapper.Map <BranchCommission, BranchCommissionDto>(branchCommission);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(branchCommissionDto);
        }
예제 #3
0
        public ClientAttatchmentDto Insert(ClientAttatchmentDto dto)
        {
            ClientAttatchmentDto clientAttatchmentDto = null;

            try
            {
                var clientAttatchment = Mapper.Map <ClientAttatchmentDto, ClientAttatchment>(dto);
                clientAttatchment.CreatedBy = _appSession.GetUserName();
                clientAttatchment.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <ClientAttatchment>().Insert(clientAttatchment);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                clientAttatchmentDto = Mapper.Map <ClientAttatchment, ClientAttatchmentDto>(clientAttatchment);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(clientAttatchmentDto);
        }
예제 #4
0
        public ProvinceDto Insert(ProvinceInsertDto dto)
        {
            ProvinceDto provinceDto = null;

            try
            {
                var province = Mapper.Map <ProvinceInsertDto, Country>(dto);
                province.CreatedBy = _appSession.GetUserName();
                province.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <Country>().Insert(province);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                provinceDto = Mapper.Map <Country, ProvinceDto>(province);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(provinceDto);
        }
        public TreasuryCashDto Insert(TreasuryCashDto dto)
        {
            TreasuryCashDto treasuryCashDto = null;

            try
            {
                var treasuryCash = Mapper.Map <TreasuryCashDto, TreasuryCash>(dto);
                treasuryCash.CreatedBy = _appSession.GetUserName();
                treasuryCash.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <TreasuryCash>().Insert(treasuryCash);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                treasuryCashDto = Mapper.Map <TreasuryCash, TreasuryCashDto>(treasuryCash);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(treasuryCashDto);
        }
예제 #6
0
        public AttachmentDto Insert(AttachmentInsertDto dto)
        {
            AttachmentDto attachmentDto = null;

            try
            {
                var attachment = Mapper.Map <AttachmentInsertDto, Attachment>(dto);
                attachment.CreatedBy = _appSession.GetUserName();
                attachment.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <Attachment>().Insert(attachment);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                attachmentDto = Mapper.Map <Attachment, AttachmentDto>(attachment);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(attachmentDto);
        }
예제 #7
0
        public PublicExpenseDto Insert(PublicExpenseInsertDto dto)
        {
            PublicExpenseDto publicExpenseDto = null;

            try
            {
                var publicExpense = Mapper.Map <PublicExpenseInsertDto, PublicExpense>(dto);

                _unitOfWork.CreateTransaction();

                publicExpense.CreatedBy = _appSession.GetUserName();
                publicExpense.IsEnabled = true;

                _unitOfWork.GenericRepository <PublicExpense>().Insert(publicExpense);

                var publicMoney = new PublicMoney()
                {
                    CreatedBy = _appSession.GetUserName(),
                    ExpenseId = publicExpense.Id
                };

                _unitOfWork.GenericRepository <PublicMoney>().Insert(publicMoney);
                _unitOfWork.Save();
                _unitOfWork.Commit();

                publicExpenseDto = Mapper.Map <PublicExpense, PublicExpenseDto>(publicExpense);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(publicExpenseDto);
        }
        public BranchCashDto Insert(BranchCashInsertDto dto)
        {
            BranchCashDto branchCashDto = null;

            try
            {
                var branchCash = Mapper.Map <BranchCashInsertDto, BranchCash>(dto);
                branchCash.CreatedBy = _appSession.GetUserName();
                branchCash.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <BranchCash>().Insert(branchCash);
                _unitOfWork.Save();

                _unitOfWork.Commit();

                branchCashDto = Mapper.Map <BranchCash, BranchCashDto>(branchCash);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(branchCashDto);
        }
예제 #9
0
        public TreasuryMoneyActionDto GetMony(TreasuryMoneyActionInsertDto input)
        {
            TreasuryMoneyActionDto treasuryMoneyActionDto = null;

            try
            {
                decimal total = 0;

                _unitOfWork.CreateTransaction();

                var treasuryCash = _unitOfWork.GenericRepository <TreasuryCash>()
                                   .FindBy(x => x.CoinId == input.CoinId && x.TreasuryId == input.TreasuryId)
                                   .FirstOrDefault();

                if (treasuryCash != null)
                {
                    treasuryCash.Total -= input.Amount;
                    _unitOfWork.GenericRepository <TreasuryCash>().Update(treasuryCash);
                    total = treasuryCash.Total;
                }
                else
                {
                    var newTreasuryCash = new TreasuryCash()
                    {
                        CoinId     = input.CoinId,
                        TreasuryId = input.TreasuryId,
                        Total      = input.Amount,
                        CreatedBy  = _appSession.GetUserName(),
                        Created    = DateTime.Now
                    };
                    _unitOfWork.GenericRepository <TreasuryCash>().Insert(newTreasuryCash);
                    total = newTreasuryCash.Total;
                }

                var treasuryMoneyAction = new TreasuryMoneyAction()
                {
                    Total      = total,
                    TreasuryId = input.TreasuryId,
                    CoinId     = input.CoinId,
                    Amount     = -input.Amount,
                    Created    = DateTime.Now,
                    CreatedBy  = _appSession.GetUserName()
                };
                _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(treasuryMoneyAction);

                _unitOfWork.Save();

                _unitOfWork.Commit();

                treasuryMoneyActionDto = Mapper.Map <TreasuryMoneyAction, TreasuryMoneyActionDto>(treasuryMoneyAction);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }
            return(treasuryMoneyActionDto);
        }
예제 #10
0
        public UserDetailDto GiveTreasury(Guid userId, int treasuryId)
        {
            UserDetailDto dto = null;

            try
            {
                _unitOfWork.CreateTransaction();

                var userTreasury = _unitOfWork.GenericRepository <UserTreasuery>().FindBy(x => x.UserId == userId && x.DeliveryDate == null).LastOrDefault();
                if (userTreasury != null)
                {
                    userTreasury.DeliveryDate = DateTime.Now;
                    userTreasury.Modified     = DateTime.Now;
                    userTreasury.ModifiedBy   = _appSession.GetUserName();
                    _unitOfWork.GenericRepository <UserTreasuery>().Update(userTreasury);
                }

                var treusery = _unitOfWork.GenericRepository <Treasury>().FindBy(x => x.Id == treasuryId).FirstOrDefault();
                if (treusery != null)
                {
                    treusery.IsAvilable = false;
                    _unitOfWork.GenericRepository <Treasury>().Update(treusery);
                    var newUserTreasery = new UserTreasuery()
                    {
                        UserId     = userId,
                        TreasuryId = treasuryId,
                        Created    = DateTime.Now,
                        CreatedBy  = _appSession.GetUserName()
                    };

                    _unitOfWork.GenericRepository <UserTreasuery>().Insert(newUserTreasery);
                }

                _unitOfWork.Save();
                _unitOfWork.Commit();

                dto = GetUserWithTreasuries(userId);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }

            return(dto);
        }
예제 #11
0
        public CoinDto Insert(CoinInsertDto dto)
        {
            CoinDto coinDto = null;

            try
            {
                var coin = Mapper.Map <CoinInsertDto, Coin>(dto);
                coin.CreatedBy = _appSession.GetUserName();
                coin.IsEnabled = true;
                _unitOfWork.CreateTransaction();

                _unitOfWork.GenericRepository <Coin>().Insert(coin);

                CreateBranchCashForAllBranches(coin);
                CreateTreasuryCashForAllTreasures(coin);
                CreateCompanyCashForAllCompanies(coin);
                CreateClientCashForAllClients(coin);

                _unitOfWork.Save();

                _unitOfWork.Commit();

                coinDto = Mapper.Map <Coin, CoinDto>(coin);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }

            return(coinDto);
        }
        private void CheckForAdd(IList <string> permNames, Role role)
        {
            _unitOfWork.CreateTransaction();
            foreach (var permName in permNames)
            {
                var perms = _unitOfWork.GenericRepository <Permission>().FindBy(x => x.Role.RoleId == role.RoleId && x.Name == permName);
                if (perms.Count() == 0 || perms == null)
                {
                    var permission = new Permission()
                    {
                        Name          = permName,
                        GrantedByUser = _appSession.GetUserName(),
                        GrantedDate   = DateTime.Now,
                        Role          = role
                    };

                    _unitOfWork.GenericRepository <Permission>().Insert(permission);
                }
            }

            _unitOfWork.Save();
            _unitOfWork.Commit();
        }
        public bool SaveInnerTransactions(InnerTransactionInsertListDto innerTransacrions)
        {
            try
            {
                _unitOfWork.CreateTransaction();

                var mainCompanyId = innerTransacrions.MainCompanyId;
                var note          = innerTransacrions.Note;
                //new line
                var mainCompnayCashe            = _unitOfWork.GenericRepository <CompanyCash>().FindBy(x => x.CompanyId == mainCompanyId);
                var incomeTransactionCollection = new IncomeTransactionCollection()
                {
                    CompnayId = mainCompanyId,
                    Note      = note,
                    CreatedBy = _appSession.GetUserName()
                };
                _unitOfWork.GenericRepository <IncomeTransactionCollection>().Insert(incomeTransactionCollection);

                foreach (var innerTransacrion in innerTransacrions.Transactions)
                {
                    var moneyAction = IncomeTrasactionForClient(innerTransacrion, mainCompanyId, innerTransacrions.Date, incomeTransactionCollection);

                    switch (innerTransacrion.TypeOfPay)
                    {
                    case TypeOfPay.Cash:
                        break;

                    case TypeOfPay.ClientsReceivables:
                    {
                        AgentBalnaceArbitrage(innerTransacrion, moneyAction);
                    }
                    break;

                    case TypeOfPay.CompaniesReceivables:
                    {
                        CompanyBlanceArbitrage(innerTransacrion, moneyAction);
                    }
                    break;

                    default:
                    {
                        return(false);
                    }
                    }
                    MaiCompanyBalanceArbitrage(mainCompnayCashe.Where(c => c.CoinId == innerTransacrion.CoinId).First(), innerTransacrion, mainCompanyId, moneyAction);
                }

                _unitOfWork.Save();
                _unitOfWork.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                Tracing.SaveException(ex);
                return(false);
            }
        }
예제 #14
0
        public bool ExchangeForBranch(int sellingCoinId, int purchasingCoinId, decimal firstAmount)
        {
            try
            {
                int treasuryId       = _appSession.GetCurrentTreasuryId();
                var secondCoinAmount = CalcForFirstCoin(sellingCoinId, purchasingCoinId, firstAmount);

                var mainCoin            = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.IsMainCoin == true).FirstOrDefault();
                var firstCoinExchange   = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.CoinId == sellingCoinId).FirstOrDefault();
                var secoundCoinExchange = _unitOfWork.GenericRepository <BranchCash>().FindBy(c => c.CoinId == purchasingCoinId).FirstOrDefault();


                _unitOfWork.CreateTransaction();


                var exchange = new Exchange()
                {
                    BranchId           = BranchHelper.Id,
                    FirstCoinId        = sellingCoinId,
                    SecoundCoinId      = purchasingCoinId,
                    AmountOfFirstCoin  = firstAmount,
                    AmoutOfSecoundCoin = secondCoinAmount,
                    MainCoinId         = mainCoin.CoinId,
                    FirstCoinExchangePriceWithMainCoin     = firstCoinExchange.ExchangePrice,
                    FirstCoinSellingPriceWithMainCoin      = firstCoinExchange.SellingPrice,
                    FirstCoinPurchasingPriceWithMainCoin   = firstCoinExchange.PurchasingPrice,
                    SecoundCoinExchangePriceWithMainCoin   = secoundCoinExchange.ExchangePrice,
                    SecoundCoinSellingPricWithMainCoin     = secoundCoinExchange.SellingPrice,
                    SecoundCoinPurchasingPriceWithMainCoin = secoundCoinExchange.PurchasingPrice
                };
                _unitOfWork.GenericRepository <Exchange>().Insert(exchange);


                var branchCaches          = _unitOfWork.GenericRepository <BranchCash>();
                var branchCashSellingCoin = branchCaches.FindBy(c => c.CoinId == sellingCoinId).FirstOrDefault();
                branchCashSellingCoin.Total -= firstAmount;
                _unitOfWork.GenericRepository <BranchCash>().Update(branchCashSellingCoin);


                var branchCashpurhesCoin = branchCaches.FindBy(c => c.CoinId == purchasingCoinId).FirstOrDefault();
                branchCashpurhesCoin.Total += secondCoinAmount;
                _unitOfWork.GenericRepository <BranchCash>().Update(branchCashpurhesCoin);



                var moneyAction = new MoneyAction()
                {
                    ExchangeId = exchange.Id
                };
                _unitOfWork.GenericRepository <MoneyAction>().Insert(moneyAction);
                var branchCashFlowForFirstCoin = new BranchCashFlow()
                {
                    BranchId    = BranchHelper.Id,
                    MoenyAction = moneyAction,
                    CoinId      = sellingCoinId,
                    Total       = branchCashSellingCoin.Total,
                    Amount      = -firstAmount,
                    TreasuryId  = treasuryId,
                };
                _unitOfWork.GenericRepository <BranchCashFlow>().Insert(branchCashFlowForFirstCoin);
                var sellingCoinTreasuryCash = _unitOfWork.GenericRepository <TreasuryCash>().FindBy(C => C.TreasuryId == treasuryId && C.CoinId == sellingCoinId).FirstOrDefault();
                sellingCoinTreasuryCash.Total -= firstAmount;
                _unitOfWork.GenericRepository <TreasuryCash>().Update(sellingCoinTreasuryCash);
                TreasuryMoneyAction sellingCoinTreasuryMoeyAction = new TreasuryMoneyAction()
                {
                    Amount         = -firstAmount,
                    CoinId         = sellingCoinId,
                    TreasuryId     = treasuryId,
                    Total          = sellingCoinTreasuryCash.Total,
                    BranchCashFlow = branchCashFlowForFirstCoin,
                };
                _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(sellingCoinTreasuryMoeyAction);
                var mainTreasuryId = _appSession.GetMainTreasury();
                if (mainTreasuryId != treasuryId)
                {
                    var mainTruseryMoneyAction = new TreasuryMoneyAction()
                    {
                        TreasuryId     = mainTreasuryId,
                        Amount         = -firstAmount,
                        CoinId         = sellingCoinId,
                        BranchCashFlow = branchCashFlowForFirstCoin,
                        CreatedBy      = _appSession.GetUserName()
                    };

                    _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(mainTruseryMoneyAction);
                }


                var branChCashFlowForSecoundCoin = new BranchCashFlow()
                {
                    BranchId     = BranchHelper.Id,
                    CoinId       = purchasingCoinId,
                    MonyActionId = moneyAction.Id,
                    Total        = branchCashpurhesCoin.Total,
                    Amount       = secondCoinAmount,
                    TreasuryId   = treasuryId,
                };
                _unitOfWork.GenericRepository <BranchCashFlow>().Insert(branChCashFlowForSecoundCoin);

                var secoundCoinTreasuryCash = _unitOfWork.GenericRepository <TreasuryCash>().FindBy(C => C.TreasuryId == treasuryId && C.CoinId == sellingCoinId).FirstOrDefault();
                secoundCoinTreasuryCash.Total += secondCoinAmount;
                _unitOfWork.GenericRepository <TreasuryCash>().Update(secoundCoinTreasuryCash);
                TreasuryMoneyAction secoundCoinTreasuryMoeyAction = new TreasuryMoneyAction()
                {
                    Amount         = +secondCoinAmount,
                    CoinId         = purchasingCoinId,
                    TreasuryId     = treasuryId,
                    Total          = secoundCoinTreasuryCash.Total,
                    BranchCashFlow = branChCashFlowForSecoundCoin,
                };
                _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(secoundCoinTreasuryMoeyAction);

                if (mainTreasuryId != treasuryId)
                {
                    var mainTruseryMoneyActionSecoundCoin = new TreasuryMoneyAction()
                    {
                        TreasuryId     = mainTreasuryId,
                        Amount         = +secondCoinAmount,
                        BranchCashFlow = branChCashFlowForSecoundCoin,
                        CoinId         = purchasingCoinId,
                        CreatedBy      = _appSession.GetUserName()
                    };

                    _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(mainTruseryMoneyActionSecoundCoin);
                }
                _unitOfWork.Save();
                _unitOfWork.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                return(false);
            }
        }
        public TransactionDto DileverTransaction(int transactionId)
        {
            TransactionDto transactionDto = null;

            try
            {
                _unitOfWork.CreateTransaction();
                var transaction    = _unitOfWork.GenericRepository <Transaction>().GetById(transactionId);
                int treasuryId     = _appSession.GetCurrentTreasuryId();
                var mainTreasuryId = _appSession.GetMainTreasury();
                if (transaction != null)
                {
                    transaction.Deliverd   = true;
                    transaction.ModifiedBy = _appSession.GetUserName();
                    _unitOfWork.GenericRepository <Transaction>().Update(transaction);

                    var branchCash = _unitOfWork.GenericRepository <BranchCash>().FindBy(x => x.CoinId == transaction.CoinId).FirstOrDefault();
                    if (branchCash != null)
                    {
                        branchCash.Total -= transaction.Amount;
                        _unitOfWork.GenericRepository <BranchCash>().Update(branchCash);
                    }

                    var treasuryCash = _unitOfWork.GenericRepository <TreasuryCash>()
                                       .FindBy(x => x.CoinId == transaction.CoinId && x.TreasuryId == treasuryId).FirstOrDefault();
                    if (treasuryCash != null)
                    {
                        treasuryCash.Total -= transaction.Amount;
                        _unitOfWork.GenericRepository <TreasuryCash>().Update(treasuryCash);
                    }

                    int moneyActinId = transaction.MoneyActionId();

                    var branchCashFLow = new BranchCashFlow()
                    {
                        Total        = branchCash.Total,
                        Amount       = -transaction.Amount,
                        MonyActionId = moneyActinId,
                        BranchId     = BranchHelper.Id,
                        CoinId       = transaction.CoinId,
                        TreasuryId   = _appSession.GetCurrentTreasuryId(),
                        CreatedBy    = _appSession.GetUserName()
                    };
                    _unitOfWork.GenericRepository <BranchCashFlow>().Insert(branchCashFLow);

                    var treuseryMoenyAction = new TreasuryMoneyAction()
                    {
                        Amount         = -transaction.Amount,
                        Total          = treasuryCash.Total,
                        CoinId         = transaction.CoinId,
                        TreasuryId     = _appSession.GetCurrentTreasuryId(),
                        BranchCashFlow = branchCashFLow,
                        CreatedBy      = _appSession.GetUserName()
                    };
                    _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(treuseryMoenyAction);

                    if (mainTreasuryId != treasuryId)
                    {
                        var mainTruseryMoneyAction = new TreasuryMoneyAction()
                        {
                            Amount         = -transaction.Amount,
                            TreasuryId     = mainTreasuryId,
                            CoinId         = transaction.CoinId,
                            BranchCashFlow = branchCashFLow
                        };

                        _unitOfWork.GenericRepository <TreasuryMoneyAction>().Insert(mainTruseryMoneyAction);
                    }
                    _unitOfWork.Save();
                    _unitOfWork.Commit();

                    transactionDto = Mapper.Map <Transaction, TransactionDto>(transaction);
                }
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(transactionDto);
        }