예제 #1
0
        private void FillAccountCategoryDetails(Account account)
        {
            var query           = string.Format("SELECT * FROM ACCOUNTSCATEGORIES WHERE ACCOUNTID={0}", account.AccountId);
            var dataBaseHandler = new DataBaseHandler();
            var dt           = dataBaseHandler.RunQuery(query);
            var categoryList = new List <int>();

            foreach (DataRow row in dt.Rows)
            {
                categoryList.Add((Int32)row.ItemArray[1]);
            }
            account.CategoryList = categoryList;
        }
예제 #2
0
        public List <Category> GetCategories()
        {
            var categories      = new List <Category>();
            var query           = "SELECT * FROM CATEGORIES";
            var dataBaseHandler = new DataBaseHandler();
            var dt = dataBaseHandler.RunQuery(query);

            foreach (DataRow row in dt.Rows)
            {
                categories.Add(new Category {
                    CategoryId = (Int32)row.ItemArray[0], CategoryName = row.ItemArray[1].ToString()
                });
            }
            return(categories);
        }
예제 #3
0
        public Account GetAccountDetails([FromUri] int accountId)
        {
            Account account = new Account {
                AccountId = accountId
            };
            var query           = string.Format("SELECT * FROM ACCOUNTS WHERE ACCOUNTID={0}", accountId);
            var dataBaseHandler = new DataBaseHandler();
            var dt = dataBaseHandler.RunQuery(query);

            if (dt.Rows.Count == 1)
            {
                account.FirstName = dt.Rows[0].ItemArray[1].ToString();
                account.LastName  = dt.Rows[0].ItemArray[2].ToString();
                FillAccountCategoryDetails(account);
                return(account);
            }
            account.FirstName = "Empty";
            account.LastName  = "Empty";
            return(account);
        }
        private ProductAccount GenerateProductAccount(int accountId, string barcode)
        {
            var productAccount  = new ProductAccount();
            var query           = string.Format("SELECT p.*, ac.CategoryId FROM Products p JOIN ProductsCategories pc ON p.ProductId=pc.ProductId JOIN AccountsCategories ac ON pc.CategoryId=ac.CategoryId WHERE P.ProductId={0} AND ac.AccountId={1}", barcode, accountId);
            var dataBaseHandler = new DataBaseHandler();
            var dt = dataBaseHandler.RunQuery(query);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            productAccount.ProductId   = Int32.Parse(barcode);
            productAccount.ProductName = dt.Rows[0].ItemArray[1].ToString();
            productAccount.SalePrice   = (decimal)dt.Rows[0].ItemArray[2];
            var categories = new List <int>();

            foreach (DataRow row in dt.Rows)
            {
                categories.Add((Int32)row.ItemArray[3]);
            }
            productAccount.Categories = categories;
            return(productAccount);
        }