Beispiel #1
0
        // Read all data from database and add it to bank
        private List <Account> ReadFromDatabase()
        {
            List <Account> accounts = new List <Account>();

            using (MyDbContext db = new MyDbContext())
            {
                foreach (var item in db.AccountsData)
                {
                    Account acc;
                    if (item.Type == "Deposit")
                    {
                        int         id   = item.AccountId;
                        float       pers = Bank <Account> .DEPOSIT_PERCENTAGE;
                        AccountType type = AccountType.Deposit;
                        acc = new DepositAccount(item.Sum, pers, type, (DateTime)item.Date, id) as Account;
                    }
                    else
                    {
                        int         id   = item.AccountId;
                        float       pers = 0;
                        AccountType type = AccountType.Ordinary;
                        acc = new DemandAccount(item.Sum, pers, type, id) as Account;
                    }
                    if (acc != null)
                    {
                        accounts.Add(acc);
                    }
                }
            }
            return(accounts);
        }
Beispiel #2
0
        public static bool CheckAccount(ResultObject res, DemandAccount demand)
        {
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                res.ErrorCodes.Add(BusinessErrorCodes.ToText(accountCheck));
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public static int CheckAccount(DemandAccount demand)
        {
            if ((demand & DemandAccount.NotDemo) == DemandAccount.NotDemo)
            {
                // should make a check if the account is not in demo mode
                if (User.IsDemo)
                {
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_DEMO);
                }
            }

            if ((demand & DemandAccount.IsActive) == DemandAccount.IsActive)
            {
                // check is the account is active
                if (User.Status == UserStatus.Pending)
                {
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_PENDING);
                }
                else if (User.Status == UserStatus.Suspended)
                {
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_SUSPENDED);
                }
                else if (User.Status == UserStatus.Cancelled)
                {
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_CANCELLED);
                }
            }

            if ((demand & DemandAccount.IsAdmin) == DemandAccount.IsAdmin)
            {
                // should make a check if the account has Admin role
                if (!User.IsInRole(ROLE_ADMINISTRATOR))
                {
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_SHOULD_BE_ADMINISTRATOR);
                }
            }

            if ((demand & DemandAccount.IsReseller) == DemandAccount.IsReseller)
            {
                // should make a check if the account has Admin role
                if (!User.IsInRole(ROLE_RESELLER))
                {
                    return(BusinessErrorCodes.ERROR_USER_ACCOUNT_SHOULD_BE_RESELLER);
                }
            }

            return(0);
        }
        public static int CheckAccount(DemandAccount demand)
        {
            if ((demand & DemandAccount.NotDemo) == DemandAccount.NotDemo)
            {
                // should make a check if the account is not in demo mode
                if (User.IsDemo)
                    return BusinessErrorCodes.ERROR_USER_ACCOUNT_DEMO;
            }

            if ((demand & DemandAccount.IsActive) == DemandAccount.IsActive)
            {
                // check is the account is active
                if (User.Status == UserStatus.Pending)
                    return BusinessErrorCodes.ERROR_USER_ACCOUNT_PENDING;
                else if (User.Status == UserStatus.Suspended)
                    return BusinessErrorCodes.ERROR_USER_ACCOUNT_SUSPENDED;
                else if (User.Status == UserStatus.Cancelled)
                    return BusinessErrorCodes.ERROR_USER_ACCOUNT_CANCELLED;
            }

            if ((demand & DemandAccount.IsAdmin) == DemandAccount.IsAdmin)
            {
                // should make a check if the account has Admin role
                if (!User.IsInRole(ROLE_ADMINISTRATOR))
                    return BusinessErrorCodes.ERROR_USER_ACCOUNT_SHOULD_BE_ADMINISTRATOR;
            }

            if ((demand & DemandAccount.IsReseller) == DemandAccount.IsReseller)
            {
                // should make a check if the account has Admin role
                if (!User.IsInRole(ROLE_RESELLER))
                    return BusinessErrorCodes.ERROR_USER_ACCOUNT_SHOULD_BE_RESELLER;
            }

            return 0;
        }
 public static bool CheckAccount(ResultObject res, DemandAccount demand)
 {
     int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
     if (accountCheck < 0)
     {
         res.ErrorCodes.Add(BusinessErrorCodes.ToText(accountCheck));
         return false;
     }
     return true;
 }