コード例 #1
0
        public void AddBattery(Battery battery, List<Cart> list)
        {
            var cart = new Cart
            {
                GoodsId = battery.Id,
                GoodsCategory = "Batteries",
                Price = battery.Price,
                Count = 1
            };
            var flg = 1;
            foreach (Cart item in list)
            {
                if (item.GoodsId == battery.Id && item.GoodsCategory == "Batteries")
                {
                    item.Count++;
                    flg = 0;
                    break;

                }
            }
            if (flg == 1)
            {
                list.Add(cart);
            }
        }
コード例 #2
0
        public void AddBattery(Battery battery)
        {
            using (var db = new ShopContext())
            {
                var prop = new Property
                {
                    Name = "Capacity",
                    ValueInt = battery.Capacity,
                };

                var prop2 = new Property
                {
                    Name = "Voltage",
                    ValueInt = battery.Voltage,
                };

                var item = new Commodity
                {
                    Model = battery.Model,
                    Price = battery.Price,
                    Producer = battery.Producer,
                    Category = "Batteries"
                };

                db.DbGoods.Add(item);
                prop.Goods.Add(item);
                prop2.Goods.Add(item);
                db.DbProperties.Add(prop);
                db.DbProperties.Add(prop2);
                db.SaveChanges();

            }
        }
コード例 #3
0
        public List<Battery> GetBatteries()
        {
            var goods = _repository.GetGoods();

            var batteries = from entity in goods
                            where entity.Category == "Batteries"
                            select entity;
            var listReturn = new List<Battery>();

            foreach (var item in batteries)
            {
                var battery = new Battery()
                {
                    Id = item.Id,
                    Model = item.Model,
                    Producer = item.Producer,
                    Price = item.Price,

                    //Voltage = item.Properties[],
                    //Capacity = item.Properties.Select()

                };
                foreach (var prop in item.Properties.Where(prop => prop.Name == "Capacity"))
                {
                    battery.Capacity = prop.ValueInt;
                }
                foreach (var prop in item.Properties.Where(prop => prop.Name == "Voltage"))
                {
                    battery.Voltage = prop.ValueInt;
                }

                listReturn.Add(battery);
            }
            return listReturn;
        }
コード例 #4
0
        public JsonResult AddBattery(Battery battery)
        {
            if (ModelState.IsValid)
            {
                var sessionCart = (List<Cart>)Session["CartList"];

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

            var allErrors = ModelState.Values.SelectMany(v => v.Errors);
            return Json(allErrors);
        }
コード例 #5
0
 public JsonResult Add(Battery battery)
 {
     _service.AddBattery(battery);
     return Json(new { item = "Added" }, JsonRequestBehavior.AllowGet);
 }
コード例 #6
0
        public Battery GetBattery(int id)
        {
            var goods = _repository.GetGoods();

            var item = (from entity in goods
                        where entity.Id == id
                        where entity.Category == "Batteries"
                        select entity).FirstOrDefault();
            if (item == null) return null;
            var battery = new Battery()
            {
                Id = item.Id,
                Model = item.Model,
                Producer = item.Producer,
                Price = item.Price,
            };
            foreach (var prop in item.Properties.Where(prop => prop.Name == "Capacity"))
            {
                battery.Capacity = prop.ValueInt;
            }
            foreach (var prop in item.Properties.Where(prop => prop.Name == "Voltage"))
            {
                battery.Voltage = prop.ValueInt;
            }
            return battery;
        }
コード例 #7
0
 public void AddBattery(Battery battery)
 {
     _repository.AddBattery(battery);
 }