Exemplo n.º 1
0
        public void AddMemoryCard(MemoryCard memoryCard, List<Cart> list)
        {
            var cart = new Cart
            {
                GoodsId = memoryCard.Id,
                GoodsCategory = "MemoryCards",
                Price = memoryCard.Price,
                Count = 1
            };
            var flg = 1;
            foreach (Cart item in list)
            {
                if (item.GoodsId == memoryCard.Id && item.GoodsCategory == "MemoryCards")
                {
                    item.Count++;
                    flg = 0;
                    break;

                }
            }
            if (flg == 1)
            {
                list.Add(cart);
            }
        }
        public MemoryCard GetMemoryCard(int id)
        {
            var goods = _repository.GetGoods();

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

            foreach (var prop in item.Properties.Where(prop => prop.Name == "Size"))
            {
                memoryCard.Size = prop.ValueInt;
            }
            foreach (var prop in item.Properties.Where(prop => prop.Name == "WriteSpeed"))
            {
                memoryCard.WriteSpeed = prop.ValueInt;
            }
            foreach (var prop in item.Properties.Where(prop => prop.Name == "ReadSpeed"))
            {
                memoryCard.ReadSpeed = prop.ValueInt;
            }

            return memoryCard;
        }
Exemplo n.º 3
0
        public JsonResult AddMemoryCard(MemoryCard memoryCard)
        {
            if (ModelState.IsValid)
            {
                var sessionCart = (List<Cart>)Session["CartList"];

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

            var allErrors = ModelState.Values.SelectMany(v => v.Errors);
            return Json(allErrors);
        }
Exemplo n.º 4
0
        public void AddMemoryCard(MemoryCard memoryCard)
        {
            using (var db = new ShopContext())
            {
                var size = new Property
                {
                    Name = "Size",
                    ValueInt = memoryCard.Size,
                };

                var writeSpeed = new Property
                {
                    Name = "WriteSpeed",
                    ValueInt = memoryCard.WriteSpeed,
                };

                var readSpeed = new Property
                {
                    Name = "ReadSpeed",
                    ValueInt = memoryCard.ReadSpeed,
                };

                var item = new Commodity
                {
                    Model = memoryCard.Model,
                    Price = memoryCard.Price,
                    Producer = memoryCard.Producer,
                    Category = "MemoryCards"
                };

                db.DbGoods.Add(item);
                writeSpeed.Goods.Add(item);
                readSpeed.Goods.Add(item);
                size.Goods.Add(item);

                db.DbProperties.Add(size);
                db.DbProperties.Add(readSpeed);
                db.DbProperties.Add(writeSpeed);
                db.SaveChanges();

            }
        }
 public JsonResult Add(MemoryCard memoryCard)
 {
     _service.AddMemoryCard(memoryCard);
     return Json(new { item = "Added" }, JsonRequestBehavior.AllowGet);
 }
        public List<MemoryCard> GetMemoryCards()
        {
            var goods = _repository.GetGoods();

            var memorycards = from entity in goods
                              where entity.Category == "MemoryCards"
                              select entity;
            var listReturn = new List<MemoryCard>();

            foreach (var item in memorycards)
            {
                var memoryCard = new MemoryCard()
                {
                    Id = item.Id,
                    Model = item.Model,
                    Producer = item.Producer,
                    Price = item.Price,
                };

                foreach (var prop in item.Properties.Where(prop => prop.Name == "Size"))
                {
                    memoryCard.Size = prop.ValueInt;
                }
                foreach (var prop in item.Properties.Where(prop => prop.Name == "WriteSpeed"))
                {
                    memoryCard.WriteSpeed = prop.ValueInt;
                }
                foreach (var prop in item.Properties.Where(prop => prop.Name == "ReadSpeed"))
                {
                    memoryCard.ReadSpeed = prop.ValueInt;
                }
                listReturn.Add(memoryCard);
            }
            return listReturn;
        }
 public void AddMemoryCard(MemoryCard memoryCard)
 {
     _repository.AddMemoryCard(memoryCard);
 }