public void SaveBasket(BasketModelAPI basketInfo, string AuthUserId) { // Start filling the basket detail model that will be save to the db List <BasketDetailDBModel> details = new List <BasketDetailDBModel>(); foreach (var item in basketInfo.BasketDetails) { var detail = new BasketDetailDBModel { ProductId = item.ProductId, Quantity = item.Quantity }; // Get the information about this product var ProductInfo = GlobalConfig.Connection.GetProductById(detail.ProductId); if (ProductInfo == null) { throw new Exception($"The product Id of {detail.ProductId} could not be found in the database"); } detail.Price = ProductInfo.Price * detail.Quantity; details.Add(detail); } //create the Basket Database model BasketDBModel basket = new BasketDBModel { TotalAmount = details.Sum(x => x.Price), AuthUserId = AuthUserId }; // Save the Basket BD model to the database and //Get the ID from the basket model SqlDataAccess sql = new SqlDataAccess(); basket.Id = sql.SaveDataGetId("dbo.spBasket_Insert", basket, "SingularTestJacquesData"); //Finish filling in the basket detail model foreach (var item in details) { item.BasketId = basket.Id; //Save the sale detail models sql.SaveData("dbo.spBasketDetail_Insert", item, "SingularTestJacquesData"); } }
public void SaveBasket(BasketModelAPI basket, string AuthUserId) { throw new NotImplementedException(); }