Beispiel #1
0
        public ProductModel GetProductById(int productId)
        {
            SqlDataAcces sql = new SqlDataAcces();

            var output = sql.LoadData <ProductModel, dynamic>("[dbo].[spProducts_GetById]", new { id = productId }, "RMDatabase").FirstOrDefault();

            return(output);
        }
Beispiel #2
0
        public List <ProductModel> GetProducts()
        {
            SqlDataAcces sql = new SqlDataAcces();

            var output = sql.LoadData <ProductModel, dynamic>("[dbo].[spProducts_GetAll]", new { }, "RMDatabase");

            return(output);
        }
Beispiel #3
0
        public List <UserModel> GetUserById(string Id)
        {
            SqlDataAcces sql = new SqlDataAcces();

            var p = new { user_id = Id };

            var output = sql.LoadData <UserModel, dynamic>("dbo.spUserLookup", p, "VTFData");

            return(output);
        }
Beispiel #4
0
        public List <EventModel> GetEventsByMonth(EventLookupModel eventLookup)
        {
            SqlDataAcces sql = new SqlDataAcces();

            var p = new { month = eventLookup.date, status = eventLookup.status };

            var output = sql.LoadData <EventModel, dynamic>("dbo.spEventsLookup", p, "VTFData");

            return(output);
        }
Beispiel #5
0
        public List <UserModel> GetUserById(string id)
        {
            SqlDataAcces sql = new SqlDataAcces();

            var p = new
            {
                Id = id
            };

            var output = sql.LoadData <UserModel, dynamic>("[dbo].[spUserLookUp]", p, "RMDatabase");

            return(output);
        }
        public void SaveSale(SaleModel saleInfo, string userId)
        {
            // TODO: Make this SOLID/DRY/Better
            List <SaleDetailDbModel> saleDetails = new List <SaleDetailDbModel>();
            ProductData product = new ProductData();
            var         taxRate = ConfigHelper.GetTaxRate();

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

                //TODO: Additional SaleDetail information
                var productInfo = product.GetProductById(detail.ProductId);

                if (productInfo == null)
                {
                    throw new Exception($"The 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) / 100;
                }

                saleDetails.Add(detail);
            }


            //SaleDbModel to save to database
            SaleDbModel sale = new SaleDbModel
            {
                SubTotal  = saleDetails.Sum(x => x.PurchasePrice),
                Tax       = saleDetails.Sum(x => x.Tax),
                CashierId = userId,
            };

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


            //Save Sales record
            SqlDataAcces sql = new SqlDataAcces();

            sql.SaveData("dbo.spSales_Insert", sale, "RMDatabase");


            //Get the ID from Sales table
            sale.Id = sql.LoadData <int, dynamic>("dbo.spSales_Latest",
                                                  new { CashierId = sale.CashierId, SaleDate = sale.SaleDate },
                                                  "RMDatabase").FirstOrDefault();


            //Finish filling Sales database model for insertion
            foreach (var item in saleDetails)
            {
                item.SaleId = sale.Id;

                //Save SaleDetails records.
                //If SaveData is being called too much (eg: 1000 calls/time), you can create table parameter and pass all values in 1 table.
                sql.SaveData("dbo.spSaleDetails_Insert", item, "RMDatabase");
            }
        }