Esempio n. 1
0
        public PartialViewResult Sepet()
        {
            HttpCookie cartCookie = Request.Cookies["cart"];
            SepetDto   dto        = new SepetDto();

            dto.SepetIcerik = new List <SepetDetayDto>();
            if (cartCookie != null)
            {
                dto = new JavaScriptSerializer().Deserialize <SepetDto>(cartCookie.Value);
            }

            return(PartialView("Partial/_sepet", dto));
        }
Esempio n. 2
0
        public JsonResult SepeteEkle(SepetDetayDto model)
        {
            SepetDto             returnSepet;
            JavaScriptSerializer js         = new JavaScriptSerializer();
            HttpCookie           cartCookie = new HttpCookie("cart");

            cartCookie.HttpOnly = false;
            cartCookie.Expires  = DateTime.Now.AddYears(1);

            if (Request.Cookies["cart"] != null)
            {
                string cartInfo = Request.Cookies["cart"].Value;


                SepetDto sepet = js.Deserialize <SepetDto>(cartInfo);
                if (sepet.SepetIcerik == null)
                {
                    sepet.SepetIcerik = new List <SepetDetayDto>();
                }
                if (sepet.SepetIcerik.Any(x => x.UrunId == model.UrunId))
                {
                    var item = sepet.SepetIcerik.FirstOrDefault(x => x.UrunId == model.UrunId);
                    item.Adet += model.Adet;
                }
                else
                {
                    sepet.SepetIcerik.Add(model);
                }

                returnSepet = Servis.Urun.SepetGetir(sepet.SepetIcerik);
                string sepetJson = js.Serialize(returnSepet);
                cartCookie.Value = sepetJson;
            }
            else
            {
                List <SepetDetayDto> sepetDetayi = new List <SepetDetayDto>();
                sepetDetayi.Add(model);
                returnSepet = Servis.Urun.SepetGetir(sepetDetayi);
                string sepetJson = js.Serialize(returnSepet);
                cartCookie.Value = sepetJson;
            }
            Response.Cookies.Add(cartCookie);

            return(Json(returnSepet, JsonRequestBehavior.AllowGet));
        }