public ActionResult AddtoBasket(int id)
 {
     if (Session["User"] != null)
     {
         int        Quantity = Convert.ToInt32(Request.QueryString["Quantity"]) == 0 ? 1 : Convert.ToInt32(Request.QueryString["Quantity"]);
         string     Color    = Request.QueryString["Color"] == null ? "Siyah" : Request.QueryString["Color"];
         HttpClient client   = new HttpClient();
         client.BaseAddress = new Uri(SystemConstants.webApiBaseAddress);
         HttpResponseMessage result = client.PostAsJsonAsync("api/Product/AddtoBasket", new Basket
         {
             User_ID    = (Session["User"] as User).ID,
             Product_ID = id,
             Color      = Color,
             Quantity   = Quantity
         }).Result;
         if (result.StatusCode == HttpStatusCode.OK)
         {
             string resultString = result.Content.ReadAsStringAsync().Result;
             if (resultString != "{\"Product\":null}")
             {
                 AddtoBasketResponse basket = Newtonsoft.Json.JsonConvert.DeserializeObject <AddtoBasketResponse>(resultString);
                 if (basket.Code == 1)
                 {
                     return(RedirectToAction("Index", "Home"));
                 }
             }
         }
         return(View("SystemError"));
     }
     else
     {
         return(RedirectToAction("Index", "Login"));
     }
 }
 public ActionResult RemoveProduct(int pid, int uid)
 {
     if (Session["User"] != null)
     {
         HttpClient client = new HttpClient();
         client.BaseAddress = new Uri(SystemConstants.webApiBaseAddress);
         HttpResponseMessage result = client.PostAsJsonAsync("api/Basket/RemoveProduct", new Basket
         {
             User_ID    = uid,
             Product_ID = pid,
         }).Result;
         if (result.StatusCode == HttpStatusCode.OK)
         {
             string resultString = result.Content.ReadAsStringAsync().Result;
             if (resultString != "{\"Code\":0}")
             {
                 AddtoBasketResponse basket = Newtonsoft.Json.JsonConvert.DeserializeObject <AddtoBasketResponse>(resultString);
                 if (basket.Code == 1)
                 {
                     return(RedirectToAction("Index", "Home"));
                 }
             }
         }
         return(View("SystemError"));
     }
     else
     {
         return(RedirectToAction("Index", "Login"));
     }
 }
Ejemplo n.º 3
0
        public AddtoBasketResponse AddtoBasketProduct(Basket basket)
        {
            AddtoBasketResponse response = new AddtoBasketResponse();

            using (MyDb db = new MyDb())
            {
                try
                {
                    db.Baskets.Add(basket);
                    db.SaveChanges();
                    response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SUCCESSFUL);
                }
                catch (Exception ex)
                {
                    response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR);
                }
            }
            return(response);
        }