public HttpResponseMessage GetProductCart() { ProductCartService productcartservice = new ProductCartService(); List <ProductCart> productcart = productcartservice.Read(); string productcartJSON = JsonConvert.SerializeObject(productcart, Formatting.Indented); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(productcartJSON, Encoding.UTF8, "application/json"); return(response); }
// GET: Carts/Details/5 public ActionResult Details(Guid id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Carts carts = db.Carts.Find(id); if (carts == null) { return(HttpNotFound()); } var productCartService = new ProductCartService(new ProductCartRepository()); ViewBag.Products = productCartService.GetCartProducts(id); return(View(carts)); }
public HttpResponseMessage GetProductCart(string key) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unused); ProductCartService productcartservice = new ProductCartService(); List <ProductCart> productcart = productcartservice.Read(); int id = productcartservice.GetProductCartIndex(key); if (id != -1) { ProductCart pc = productcart[id]; string productcartJSON = JsonConvert.SerializeObject(pc, Formatting.Indented); response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(productcartJSON, Encoding.UTF8, "application/json"); } else { response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); } return(response); }
public void GetTotalPriceTest() { //Arrange var cart = new ProductCartService(); var ProductA = new GetTotalPrice { }; var ProductB = new GetTotalPrice { }; var ProductC = new GetTotalPrice { }; var ProductD = new GetTotalPrice { }; // Act cart.Add(ProductA); cart.Add(ProductB); cart.Add(ProductC); cart.Add(ProductD); // Assert Assert.AreEqual(2, cart.Items[0].Quantity); }
public HttpResponseMessage DeleteProductCart(string id) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unused); try { ProductCartService pcs = new ProductCartService(); if (pcs.Delete(id)) { response = new HttpResponseMessage(HttpStatusCode.OK); } else { response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); } } catch { response = new HttpResponseMessage(HttpStatusCode.Unused); } return(response); }
public HttpResponseMessage UpdateProductCart(Object content, string key) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unused); try { ProductCart productcart = JsonConvert.DeserializeObject <ProductCart>(content.ToString()); ProductCartService pcs = new ProductCartService(); if (pcs.Update(key, productcart)) { response = new HttpResponseMessage(HttpStatusCode.OK); } else { response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); } } catch { response = Request.CreateResponse(HttpStatusCode.Unused); } return(response); }
public HttpResponseMessage PostCart(Object content) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unused); try { String productcartJSON = content.ToString(); ProductCart productcart = JsonConvert.DeserializeObject <ProductCart>(productcartJSON); ProductCartService pcs = new ProductCartService(); if (pcs.Create(productcart)) { response = new HttpResponseMessage(HttpStatusCode.OK); } else { response = new HttpResponseMessage(HttpStatusCode.ExpectationFailed); } } catch { response = new HttpResponseMessage(HttpStatusCode.Unused); } return(response); }