Exemplo n.º 1
0
        public ProductModel GetProductById(int productId)
        {
            SqlDataAccess sql = new SqlDataAccess();

            var output = sql.LoadData <ProductModel, dynamic>("dbo.spProduct_GetById", new { Id = productId }, "RMData").FirstOrDefault();

            return(output);
        }
Exemplo n.º 2
0
        public List <ProductModel> GetProducts()
        {
            SqlDataAccess sql = new SqlDataAccess();

            var output = sql.LoadData <ProductModel, dynamic>("dbo.spProduct_GetAll", new { }, "RMData");

            return(output);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method is used to read the inventory data from the database and save into a <see cref="InventoryModel"/> object and return it.
        /// </summary>
        /// <returns></returns>
        public List <InventoryModel> GetInventory()
        {
            SqlDataAccess sql = new SqlDataAccess();

            var output = sql.LoadData <InventoryModel, dynamic>("dbo.spInventory_GetAll", new { }, "RMData");

            return(output);
        }
Exemplo n.º 4
0
        public List <SaleReportModel> GetSaleReport()
        {
            SqlDataAccess sql = new SqlDataAccess();

            var output = sql.LoadData <SaleReportModel, dynamic>("dbo.spSale_SaleReport", new { }, "RMData");

            return(output);
        }
Exemplo n.º 5
0
        public List <UserModel> GetUserById(string id)
        {
            SqlDataAccess sql = new SqlDataAccess();

            var p      = new { Id = id };
            var output = sql.LoadData <UserModel, dynamic>("dbo.spUserLookup", p, "RMData");

            return(output);
        }
Exemplo n.º 6
0
        public List <ProductModel> GetProducts()
        {
            SqlDataAccess sql = new SqlDataAccess();

            // new{} just creates an anonymous object which, in this case,
            // is just empty because we don't need this parameter here.
            var output = sql.LoadData <ProductModel, dynamic>("dbo.spProduct_GetAll",
                                                              new{}, "RMDatabase");

            return(output);
        }
Exemplo n.º 7
0
        public List <UserModel> GetUserById(string Id)
        {
            SqlDataAccess sql = new SqlDataAccess();

            var p      = new { Id = Id };
            var output = sql.LoadData <UserModel, dynamic>("dbo.spUserLookup", p, "RMData");

            foreach (UserModel user in output)
            {
                user.Id = Id;
            }
            return(output);
        }
Exemplo n.º 8
0
        public void SaveSale(SaleModel saleInfo, string cashierId)
        {
            // TODO: Make this better
            List <SaleDetailDBModel> details = new List <SaleDetailDBModel>();
            ProductData product = new ProductData();

            foreach (var item in saleInfo.SaleDetails)
            {
                var detail = new SaleDetailDBModel
                {
                    ProductId = item.ProductId,
                    Quantity  = item.Quantity
                };


                var productInfo = product.GetProductById(detail.ProductId);
                if (productInfo == null)
                {
                    throw new Exception($"ProductID {detail.ProductId} can't be found");
                }
                detail.PurchasePrice = productInfo.RetailPrice * detail.Quantity;
                if (productInfo.IsTaxable)
                {
                    detail.Tax = detail.PurchasePrice * ConfigHelper.GetTaxRate();
                }
                details.Add(detail);
            }

            SaleDBModel sale = new SaleDBModel
            {
                SubTotal  = details.Sum(x => x.PurchasePrice),
                Tax       = details.Sum(x => x.Tax),
                CashierId = cashierId
            };

            sale.Total = sale.SubTotal + sale.Tax;

            SqlDataAccess sql = new SqlDataAccess();

            sql.SaveData("dbo.spSale_Insert", sale, "RMData");

            sale.Id = sql.LoadData <int, dynamic>("dbo.spSale_Lookup", new { sale.CashierId, sale.SaleDate }, "RMData").FirstOrDefault();

            foreach (var item in details)
            {
                item.SaleId = sale.Id;
                sql.SaveData("dbo.spSaleDetail_Insert", item, "RMData");
            }
        }
Exemplo n.º 9
0
        public ProductModel GetProductById(int id)
        {
            SqlDataAccess sql = new SqlDataAccess();

            return(sql.LoadData <ProductModel, dynamic>("dbo.spProduct_GetById", new { Id = id }, "RMData").FirstOrDefault());
        }
Exemplo n.º 10
0
        public void SaveSale(SaleModel saleInfo, string cashierId)
        {
            // TODO: Make this SOLID/DRY/Better
            // Start filling in the sale detail models we will save to the database
            List <SaleDetailDbModel> details = new List <SaleDetailDbModel>();
            ProductData products             = new ProductData();
            var         taxRate = ConfigHelper.GetTaxRate() / 100;

            foreach (var item in saleInfo.SaleDetails)
            {
                var detail = new SaleDetailDbModel
                {
                    ProductId = item.ProductId,
                    Quantity  = item.Quantity
                };

                // Get the information about this product
                var productInfo = products.GetProductById(detail.ProductId);

                if (productInfo == null)
                {
                    throw new Exception($"The product Id of { detail.ProductId } could not be found in the database.");
                }

                detail.PurchasePrice = (productInfo.RetailPrice * detail.Quantity);

                if (productInfo.IsTaxable)
                {
                    detail.Tax = (detail.PurchasePrice * taxRate);
                }

                details.Add(detail);
            }

            // Create the Sale model
            SaleDbModel sale = new SaleDbModel
            {
                SubTotal  = details.Sum(x => x.PurchasePrice),
                Tax       = details.Sum(x => x.Tax),
                CashierId = cashierId
            };

            sale.Total = sale.SubTotal + sale.Tax;

            // Save the sale model
            SqlDataAccess sql = new SqlDataAccess();

            sql.SaveData("dbo.spSale_Insert", sale, "RMData");

            // Get the ID from the sale mode
            sale.Id = sql.LoadData <int, dynamic>("spSale_Lookup", new { sale.CashierId, sale.SaleDate }, "RMData")
                      .FirstOrDefault();

            // Finsh filling in the sale detail models
            foreach (var item in details)
            {
                item.SaleId = sale.Id;
                // Save the sale detail models
                sql.SaveData("dbo.spSaleDetail_Insert", item, "RMData");
            }
        }