public Monitor GetMonitor(int id)
        {
            var goods = _repository.GetGoods();

            var item = (from entity in goods
                        where entity.Id == id
                        where entity.Category == "Monitors"
                        select entity).FirstOrDefault();
            if (item == null) return null;
            var monitor = new Monitor()
            {
                Id = item.Id,
                Model = item.Model,
                Producer = item.Producer,
                Price = item.Price,
            };
            foreach (var prop in item.Properties.Where(prop => prop.Name == "Resolution"))
            {
                monitor.Resolution = prop.ValueChar;
            }
            foreach (var prop in item.Properties.Where(prop => prop.Name == "Frequency"))
            {
                monitor.Frequency = prop.ValueInt;
            }
            foreach (var prop in item.Properties.Where(prop => prop.Name == "MatrixType"))
            {
                monitor.MatrixType = prop.ValueChar;
            }

            return monitor;
        }
        public JsonResult Add(Monitor monitor)
        {
            //if (ModelState.IsValid)
               //{
               _service.AddMonitor(monitor);
               return Json(new { item = "Added" }, JsonRequestBehavior.AllowGet);
               //}
               //var allErrors = ModelState.Values.SelectMany(v => v.Errors);

               //return Json(allErrors);
        }
        public void AddMonitor(Monitor monitor)
        {
            using (var db = new ShopContext())
            {
                var resolution = new Property
                {
                    Name = "Resolution",
                    ValueChar = monitor.Resolution,
                };

                var   frequency = new Property
                {
                    Name = "Frequency",
                    ValueInt = monitor.Frequency,
                };

                var   matrixType = new Property
                {
                    Name = "MatrixType",
                    ValueChar = monitor.MatrixType,
                };

                var item = new Commodity
                {
                    Model = monitor.Model,
                    Price = monitor.Price,
                    Producer = monitor.Producer,
                    Category = "Monitors"
                };

                db.DbGoods.Add(item);
                resolution.Goods.Add(item);
                frequency.Goods.Add(item);
                matrixType.Goods.Add(item);

                db.DbProperties.Add(resolution);
                db.DbProperties.Add(frequency);
                db.DbProperties.Add(matrixType);
                db.SaveChanges();

            }
        }
示例#4
0
        public void AddMonitor(Monitor monitor, List<Cart> list)
        {
            var cart = new Cart
            {
                GoodsId = monitor.Id,
                GoodsCategory = "Monitors",
                Price = monitor.Price,
                Count = 1
            };
            var flg = 1;
            foreach (Cart item in list)
            {
                if (item.GoodsId == monitor.Id && item.GoodsCategory == "Monitors")
                {
                    item.Count++;
                    flg = 0;
                    break;

                }
            }
            if (flg == 1)
            {
                list.Add(cart);
            }
        }
        public List<Monitor> GetMonitors()
        {
            var goods = _repository.GetGoods();

            var monitors = from entity in goods
                           where entity.Category == "Monitors"
                           select entity;
            var listReturn = new List<Monitor>();

            foreach (var item in monitors)
            {
                var monitor = new Monitor()
                {
                    Id = item.Id,
                    Model = item.Model,
                    Producer = item.Producer,
                    Price = item.Price,
                };
                foreach (var prop in item.Properties.Where(prop => prop.Name == "Resolution"))
                {
                    monitor.Resolution = prop.ValueChar;
                }
                foreach (var prop in item.Properties.Where(prop => prop.Name == "Frequency"))
                {
                    monitor.Frequency = prop.ValueInt;
                }
                foreach (var prop in item.Properties.Where(prop => prop.Name == "MatrixType"))
                {
                    monitor.MatrixType = prop.ValueChar;
                }
                listReturn.Add(monitor);
            }
            return listReturn;
        }
 public void AddMonitor(Monitor monitor)
 {
     _repository.AddMonitor(monitor);
 }
        public JsonResult AddMonitor(Monitor monitor)
        {
            if (ModelState.IsValid)
            {
                var sessionCart = (List<Cart>)Session["CartList"];

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

            var allErrors = ModelState.Values.SelectMany(v => v.Errors);
            return Json(allErrors);
        }