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); }
public List <ProductModel> GetProducts() { SqlDataAccess sql = new SqlDataAccess(); var output = sql.LoadData <ProductModel, dynamic>("dbo.spProduct_GetAll", new { }, "RMData"); return(output); }
/// <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); }
public List <SaleReportModel> GetSaleReport() { SqlDataAccess sql = new SqlDataAccess(); var output = sql.LoadData <SaleReportModel, dynamic>("dbo.spSale_SaleReport", new { }, "RMData"); return(output); }
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); }
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); }
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); }
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"); } }
public ProductModel GetProductById(int id) { SqlDataAccess sql = new SqlDataAccess(); return(sql.LoadData <ProductModel, dynamic>("dbo.spProduct_GetById", new { Id = id }, "RMData").FirstOrDefault()); }
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"); } }