Exemplo n.º 1
0
        public void Set(SystemAccountType defaultAccountType, Account accountItem)
        {
            if (accountItem != null)
            {
                var defaultAccountItem = erpNodeDBContext.DefaultAccounts.Find(defaultAccountType);

                if (defaultAccountItem != null)
                {
                    defaultAccountItem.AccountItemId = accountItem.Id;
                    defaultAccountItem.AccountItem   = accountItem;
                    defaultAccountItem.LastUpdate    = DateTime.Today;
                }
                else
                {
                    defaultAccountItem = new DefaultAccount()
                    {
                        AccountType   = defaultAccountType,
                        AccountItem   = accountItem,
                        AccountItemId = accountItem.Id,
                        LastUpdate    = DateTime.Today
                    };
                    erpNodeDBContext.DefaultAccounts.Add(defaultAccountItem);
                }
            }
            erpNodeDBContext.SaveChanges();
        }
Exemplo n.º 2
0
        private static MAccount GetDefaultAccount(DefaultAccount defaultAccount, EnumReferenceType referenceType)
        {
            //check in cache first
            object obj = System.Web.HttpContext.Current.Cache[defaultAccount.ToString()];

            //if not available, set it first
            if (obj == null)
            {
                MAccount account = GetDefaultAccount(referenceType);
                //save to cache
                System.Web.HttpContext.Current.Cache[defaultAccount.ToString()] = account;
            }
            //return cache
            return(System.Web.HttpContext.Current.Cache[defaultAccount.ToString()] as MAccount);
        }
        /// <summary>
        /// Converts DTO account to account.
        /// </summary>
        /// <param name="dto">DTO account to convert.</param>
        /// <returns>Account.</returns>
        public static Account ToAccount(this AccountDTO dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            BonusSystem bonusSystem = null;

            if (dto.BonusSystemType == typeof(BaseBonusSystem).ToString())
            {
                bonusSystem = new BaseBonusSystem();
            }
            else if (dto.BonusSystemType == typeof(GoldBonusSystem).ToString())
            {
                bonusSystem = new GoldBonusSystem();
            }
            else if (dto.BonusSystemType == typeof(GoldBonusSystem).ToString())
            {
                bonusSystem = new PlatinumBonusSystem();
            }
            else
            {
                throw new InvalidCastException("Can't cast AccountDTO to Account.");
            }

            Account account = null;

            if (dto.AccountType == typeof(DefaultAccount).ToString())
            {
                account = new DefaultAccount(dto.Id, bonusSystem, dto.IsClosed);
            }
            else if (dto.AccountType == typeof(CashbackAccount).ToString())
            {
                account = new CashbackAccount(dto.Id, bonusSystem, dto.Cashback, dto.IsClosed);
                ((CashbackAccount)account).CashbackPercent = dto.CashbackPercent;
            }
            else
            {
                throw new InvalidCastException("Can't cast AccountDTO to Account.");
            }

            account.FirstName = dto.FirstName;
            account.LastName  = dto.LastName;
            account.Balance   = dto.Balance;

            return(account);
        }
Exemplo n.º 4
0
        public void Create(SystemAccountType accountType)
        {
            var defaultAccountItem = erpNodeDBContext.DefaultAccounts.Find(accountType);

            if (defaultAccountItem == null)
            {
                defaultAccountItem = new DefaultAccount()
                {
                    AccountType = accountType,
                    LastUpdate  = DateTime.Today
                };

                erpNodeDBContext.DefaultAccounts.Add(defaultAccountItem);
                erpNodeDBContext.SaveChanges();
            }
        }
        /// <inheritdoc/>
        public int CreateAccount(AccountType accountType, BonusSystemType bonusSystemType)
        {
            BonusSystem bonusSystem;

            switch (bonusSystemType)
            {
            case BonusSystemType.Base:
                bonusSystem = new BaseBonusSystem();
                break;

            case BonusSystemType.Gold:
                bonusSystem = new GoldBonusSystem();
                break;

            case BonusSystemType.Platinum:
                bonusSystem = new PlatinumBonusSystem();
                break;

            default:
                throw new InvalidOperationException("Unregistered type of bonus system.");
            }

            int     id = this.CreateId();
            Account account;

            switch (accountType)
            {
            case AccountType.DefaultAccount:
                account = new DefaultAccount(id, bonusSystem);
                break;

            case AccountType.CashbackAccount:
                account = new CashbackAccount(id, bonusSystem, 0);
                break;

            default:
                throw new InvalidOperationException("Unregistered type of account.");
            }

            this.accounts.Add(account.Id, account);
            return(account.Id);
        }
Exemplo n.º 6
0
 public void Add(DefaultAccount defaultAccountItem)
 {
     erpNodeDBContext.DefaultAccounts.Add(defaultAccountItem);
     erpNodeDBContext.SaveChanges();
 }