Esempio n. 1
0
        public static void DecreaseCostOfSmsSend(Guid userGuid, Common.SmsSendType smsSendType, decimal price, string description, Guid smsSentGuid, DataAccessBase dataAccessBase)
        {
            Business.Transaction transactionController = new Business.Transaction(dataAccessBase);
            Business.User        userController        = new Business.User(dataAccessBase);
            Common.User          user = new Common.User();

            lock (lockDecreaseCostOfSmsSend)
            {
                transactionController.BeginTransaction();
                try
                {
                    userController.Load(userGuid, user);

                    if (price > user.Credit)
                    {
                        throw new UserCreditNotEnoughException();
                    }

                    Decrease(userGuid, price, GetTypeCreditChanges(smsSendType), description, smsSentGuid, transactionController.DataAccessProvider);

                    transactionController.CommitTransaction();
                }
                catch (Exception ex)
                {
                    transactionController.RollbackTransaction();
                    throw new InnerTransactionException(ex);
                }
            }
        }
Esempio n. 2
0
        public static Guid Decrease(Guid userGuid, decimal amount, TypeCreditChanges typeCreditChanges, string description, Guid referenceGuid, DataAccessBase dataAccessProvider)
        {
            try
            {
                Business.Transaction transactionController = new Business.Transaction(dataAccessProvider);
                Business.User        userController        = new Business.User(dataAccessProvider);

                decimal currentCredit = userController.GetUserCredit(userGuid);
                if (currentCredit < amount)
                {
                    throw new Exception(Language.GetString("ErrorCredit"));
                }

                Common.Transaction transaction = new Common.Transaction();

                transaction.TypeTransaction  = (int)Business.TypeTransactions.Decrease;
                transaction.ReferenceGuid    = referenceGuid;
                transaction.TypeCreditChange = (int)typeCreditChanges;
                transaction.Description      = description;
                transaction.CreateDate       = DateTime.Now;
                transaction.CurrentCredit    = currentCredit;
                transaction.Amount           = amount;
                transaction.UserGuid         = userGuid;
                Guid transactionGuid = transactionController.Insert(transaction);

                if (transactionGuid == Guid.Empty)
                {
                    throw new Exception(Language.GetString("ErrorRecord"));
                }

                if (!userController.UpdateCredit(userGuid, transaction.CurrentCredit - amount))
                {
                    throw new Exception(Language.GetString("ErrorRecord"));
                }

                return(transactionGuid);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public static Guid Increase(Guid userGuid, decimal amount, TypeCreditChanges typeCreditChanges, string description, Guid referenceGuid, bool updateGrupPrice, DataAccessBase dataAccessProvider)
        {
            Business.Transaction transactionController = new Business.Transaction(dataAccessProvider);
            Business.User        userController        = new Business.User(dataAccessProvider);

            Common.Transaction transaction   = new Common.Transaction();
            decimal            currentCredit = userController.GetUserCredit(userGuid);

            transaction.ReferenceGuid    = referenceGuid;
            transaction.TypeTransaction  = (int)Business.TypeTransactions.Increase;
            transaction.TypeCreditChange = (int)typeCreditChanges;
            transaction.Description      = description;
            transaction.CreateDate       = DateTime.Now;
            transaction.CurrentCredit    = currentCredit;
            transaction.Amount           = amount;
            transaction.UserGuid         = userGuid;
            Guid transactionGuid = transactionController.Insert(transaction);

            if (transactionGuid == Guid.Empty)
            {
                throw new Exception(Language.GetString("ErrorRecord"));
            }

            if (updateGrupPrice)
            {
                if (!userController.UpdateCreditAndGroupPrice(userGuid, transaction.CurrentCredit + amount, amount))
                {
                    throw new Exception(Language.GetString("ErrorRecord"));
                }
            }
            else
            {
                if (!userController.UpdateCredit(userGuid, transaction.CurrentCredit + amount))
                {
                    throw new Exception(Language.GetString("ErrorRecord"));
                }
            }

            return(transactionGuid);
        }
Esempio n. 4
0
        public static bool ChangeCreditByManage(Guid userGuid, bool parentIsMainAdmin, TypeTransactions type, decimal amount, string description)
        {
            Business.Transaction transactionController = new Business.Transaction();
            transactionController.BeginTransaction();
            Guid transactionGuid;

            try
            {
                Common.User user = Facade.User.LoadUser(userGuid);
                switch (type)
                {
                case TypeTransactions.Increase:
                    if (!parentIsMainAdmin)
                    {
                        Decrease(user.ParentGuid, amount, TypeCreditChanges.Manage, string.Format(Language.GetString("ManageIncreaseCreditTransaction"), user.UserName, description), Guid.Empty, transactionController.DataAccessProvider);
                    }
                    transactionGuid = Increase(userGuid, amount, TypeCreditChanges.Manage, description, Guid.Empty, false, transactionController.DataAccessProvider);
                    CalculateBenefit(userGuid, amount, transactionGuid, transactionController.DataAccessProvider);
                    break;

                case TypeTransactions.Decrease:
                    transactionGuid = Decrease(userGuid, amount, TypeCreditChanges.Manage, description, Guid.Empty, transactionController.DataAccessProvider);
                    CalculateBenefit(userGuid, amount * -1, transactionGuid, transactionController.DataAccessProvider);
                    if (!parentIsMainAdmin)
                    {
                        Increase(user.ParentGuid, amount, TypeCreditChanges.Manage, string.Format(Language.GetString("ManageDecreaseCreditTransaction"), user.UserName, description), Guid.Empty, false, transactionController.DataAccessProvider);
                    }
                    break;
                }
                transactionController.CommitTransaction();
                return(true);
            }
            catch (Exception ex)
            {
                transactionController.RollbackTransaction();
                throw ex;
            }
        }
Esempio n. 5
0
 public static bool CalculateBenefit(Guid userGuid, decimal smsCount, Guid transactionGuid, DataAccessBase dataAccessProvider)
 {
     Business.Transaction transactionController = new Business.Transaction(dataAccessProvider);
     return(transactionController.CalculateBenefit(userGuid, smsCount, transactionGuid));
 }
Esempio n. 6
0
 public static DataTable GetPagedUsersTransaction(Guid userGuid, Guid domainGuid, string username, string query, string sortField, int pageNo, int pageSize, ref int resultCount, ref decimal totalCount)
 {
     Business.Transaction transactionController = new Business.Transaction();
     return(transactionController.GetPagedUsersTransaction(userGuid, domainGuid, username, query, sortField, pageNo, pageSize, ref resultCount, ref totalCount));
 }
Esempio n. 7
0
 public static DataTable GetPagedUserTransaction(Guid userGuid, Guid referenceGuid, string query, string sortField, int pageNo, int pageSize, ref int resultCount)
 {
     Business.Transaction transactionController = new Business.Transaction();
     return(transactionController.GetPagedUserTransaction(userGuid, referenceGuid, query, sortField, pageNo, pageSize, ref resultCount));
 }