// PUT api/productapi/5 public void Put(int id, [FromBody] Models.ProductModels value) { if (ModelState.IsValid) { //ProductModels pm = db.Products.Find(id); db.Entry(value).State = EntityState.Modified; db.SaveChanges(); } }
// GET api/productapi/5 public Models.ProductModels Get(int id) { Models.ProductModels productmodel = db.Products.Find(id); /*if (productmodel == null) * { * return HttpNotFound(); * }*/ return(productmodel); }
// POST api/productapi public Models.ProductModels Post([FromBody] Models.ProductModels value) { if (ModelState.IsValid) { db.Products.Add(value); db.SaveChanges(); } return(value); //ToDo: decide whether to send CU through post or just C. //ToDo: how to protect this method //ToDo: how should this be tested }
public double CalculateFee(Models.ProductModels product) { double fee = 0; var size = product.Length * product.Width * product.Height; //長 x 寬 x 高(公分)x 0.0000353 if (product.Length > 100 || product.Width > 100 || product.Height > 100) { fee = size * 0.0000353 * 1100 + 500; } else { fee = size * 0.0000353 * 1200; } return(fee); }
/// <summary> /// 計算運費 /// </summary> /// <param name="product">商品規格</param> /// <returns>運費</returns> public double CalculateFee(Models.ProductModels product) { double fee = 0; var weight = product.Weight; if (weight > 20) { fee = 500; } else { fee = 100 + weight * 10; } return(fee); }
public double CalculateFee(Models.ProductModels product) { double fee = 0; var feeByWeight = 80 + product.Weight * 10; var size = product.Length * product.Width * product.Height; var feeBySize = size * 0.0000353 * 1100; if (feeByWeight < feeBySize) { fee = feeByWeight; } else { fee = feeBySize; } return(fee); }