예제 #1
0
        public Earphone GetEarphone(int id)
        {
            var goods = _repository.GetGoods();

            var item = (from entity in goods
                        where entity.Id == id
                        where entity.Category == "Earphones"
                        select entity).FirstOrDefault();
            if (item == null) return null;
            var earphone = new Earphone()
            {
                Id = item.Id,
                Model = item.Model,
                Producer = item.Producer,
                Price = item.Price,
            };

            foreach (var prop in item.Properties.Where(prop => prop.Name == "CableLength"))
            {
                earphone.CableLength = prop.ValueInt;
            }
            foreach (var prop in item.Properties.Where(prop => prop.Name == "Resistance"))
            {
                earphone.Resistance = prop.ValueInt;
            }
            foreach (var prop in item.Properties.Where(prop => prop.Name == "MaxFrequency"))
            {
                earphone.MaxFrequency = prop.ValueInt;
            }

            return earphone;
        }
예제 #2
0
        public void AddEarphone(Earphone earphone, List<Cart> list)
        {
            var cart = new Cart
            {
                GoodsId = earphone.Id,
                GoodsCategory = "Earphones",
                Price = earphone.Price,
                Count = 1
            };
            var flg = 1;
            foreach (Cart item in list)
            {
                if (item.GoodsId == earphone.Id && item.GoodsCategory == "Earphones")
                {
                    item.Count++;
                    flg = 0;
                    break;

                }
            }
            if (flg == 1)
            {
                list.Add(cart);
            }
        }
예제 #3
0
        public void AddEarphone(Earphone earphone)
        {
            using (var db = new ShopContext())
            {
                var maxFrequency = new Property
                {
                    Name = "MaxFrequency",
                    ValueInt = earphone.MaxFrequency,
                };

                var resistance = new Property
                {
                    Name = "Resistance",
                    ValueInt = earphone.Resistance,
                };

                var cableLength = new Property
                {
                    Name = "CableLength",
                    ValueInt = earphone.CableLength,
                };

                var item = new Commodity
                {
                    Model = earphone.Model,
                    Price = earphone.Price,
                    Producer = earphone.Producer,
                    Category = "Earphones"
                };

                db.DbGoods.Add(item);
                cableLength.Goods.Add(item);
                resistance.Goods.Add(item);
                maxFrequency.Goods.Add(item);

                db.DbProperties.Add(maxFrequency);
                db.DbProperties.Add(resistance);
                db.DbProperties.Add(cableLength);
                db.SaveChanges();

            }
        }
예제 #4
0
        public JsonResult AddEarphone(Earphone earphone)
        {
            if (ModelState.IsValid)
            {
                var sessionCart = (List<Cart>)Session["CartList"];

                if (sessionCart == null)
                {
                    var tmp = new List<Cart>();
                    _service.AddEarphone(earphone, tmp);
                    Session["CartList"] = tmp;
                }
                else
                {
                    _service.AddEarphone(earphone, sessionCart);
                    Session["CartList"] = sessionCart;
                }
                return Json(new { item = "Added" });
            }

            var allErrors = ModelState.Values.SelectMany(v => v.Errors);
            return Json(allErrors);
        }
예제 #5
0
        public List<Earphone> GetEarphones()
        {
            var goods = _repository.GetGoods();

            var earphones = from entity in goods
                            where entity.Category == "Earphones"
                            select entity;
            var listReturn = new List<Earphone>();

            foreach (var item in earphones)
            {
                var earphone = new Earphone()
                {
                    Id = item.Id,
                    Model = item.Model,
                    Producer = item.Producer,
                    Price = item.Price,
                };

                foreach (var prop in item.Properties.Where(prop => prop.Name == "CableLength"))
                {
                    earphone.CableLength = prop.ValueInt;
                }
                foreach (var prop in item.Properties.Where(prop => prop.Name == "Resistance"))
                {
                    earphone.Resistance = prop.ValueInt;
                }
                foreach (var prop in item.Properties.Where(prop => prop.Name == "MaxFrequency"))
                {
                    earphone.MaxFrequency = prop.ValueInt;
                }
                listReturn.Add(earphone);
            }
            return listReturn;
        }
예제 #6
0
 public void AddEarphone(Earphone earphone)
 {
     _repository.AddEarphone(earphone);
 }
 public JsonResult Add(Earphone earphone)
 {
     _service.AddEarphone(earphone);
     return Json(new { item = "Added" }, JsonRequestBehavior.AllowGet);
 }