public void TestTotalValueWithDiscount() { var ps1 = new ProductSelect() { Product = new Product() { Value = 12m }, Qtd = 3, Discount = 10 }; var ps2 = new ProductSelect() { Product = new Product() { Value = 16m }, Qtd = 4, Discount = 20 }; var sc = new ShoppingCart() { ShippingTax = 10 }; sc.ProductSelects.Add(ps2); sc.ProductSelects.Add(ps1); Assert.AreEqual((decimal)3m * 12m * (1m - 10m / 100m) + 4m * 16m * (1m - 20m / 100m) + 10m, sc.TotalValueWithDiscount()); }
public void TestTotalValue() { var ps1 = new ProductSelect() { Product = new Product() { Value = 12 }, Qtd = 3 }; var ps2 = new ProductSelect() { Product = new Product() { Value = 16 }, Qtd = 4 }; var sc = new ShoppingCart() { ShippingTax = 10 }; sc.ProductSelects.Add(ps2); sc.ProductSelects.Add(ps1); Assert.AreEqual(3m * 12m + 4m * 16m + 10m, sc.TotalValue()); }
public void TestTotalWeight() { var ps1 = new ProductSelect() { Product = new Product() { Weight = 3 }, Qtd = 3 }; var ps2 = new ProductSelect() { Product = new Product() { Weight = 4 }, Qtd = 4 }; var sc = new ShoppingCart(); sc.ProductSelects.Add(ps1); sc.ProductSelects.Add(ps2); Assert.AreEqual(3 * 3 + 4 * 4, sc.TotalWeight()); }
public JsonResult GetListProductCart(int CustomerID, int productID, int unit) { List <ProductSelect> ProductData = new List <ProductSelect>(); try { ProductData product = new ProductData(); ProductSelect selectItem = new ProductSelect(); selectItem.ProductID = productID; selectItem.Unit = unit; product.GetProductPrice(ref selectItem); ProductData.Add(selectItem); return(Json(new { data = ProductData, success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json(new { data = ProductData, success = false }, JsonRequestBehavior.AllowGet)); } }
public JsonResult PostAddProduct(ProductSelect product, int CustomerID, int ContractID) { try { ContractData cd = new ContractData(); // ลบสินค้าเดิมทั้งหมด แก้จำนวนเงินสินค้าทั้งหมดในสัญญา cd.Deleted_Product_customer(CustomerID, ContractID); List <ProductSelect> products = new List <ProductSelect>(); products.Add(product); // เพิ่มสินค้า ProductData pd = new ProductData(); pd.AddProductSelect(products, CustomerID, ContractID); // getProduct By Contract ProductData dataPro = new ProductData(); IList <ProductSelect> listProductsSelect = new List <ProductSelect>(); listProductsSelect = dataPro.GetProductCustomer(CustomerID, ContractID); double ContractPayment = 0; List <ProductSelect> listProductsSelect1 = new List <ProductSelect>(); listProductsSelect1 = dataPro.ProductContractSummary(ref ContractPayment, listProductsSelect); // update จำนวนเงินสินค้าทั้งหมด cd.UpdateContractPayment(ContractID, CustomerID, ContractPayment); // คำนวณ ค่างวด / วันสิ้นสุดสัญญา cd.UpdateContractAmount_ContractExpDate(CustomerID, ContractID); return(Json(new { data = "", success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { data = ex.Message, success = false }, JsonRequestBehavior.AllowGet)); } }
public void TestUnitValue() { var p = new Product() { Value = 3m }; var ps = new ProductSelect { Product = p }; Assert.AreEqual(3m, ps.UnitValue); }
public void TestTotalValue() { var p = new Product() { Name = "Refrigerante", Value = 3m, Description = "refrigerente de cola" }; var ps = new ProductSelect() { Qtd = 3, Product = p }; Assert.AreEqual(3m * 3m, ps.TotalValue()); }
public void TestTotalValueWithDiscount2() { var p = new Product() { Name = "Refrigerante", Value = 16m, Description = "refrigerente de cola" }; var ps = new ProductSelect() { Qtd = 4, Product = p, Discount = 20 }; Assert.AreEqual(51.2m, ps.TotalValueWithDiscount()); }