Beispiel #1
0
        private void ExecuteQuery(HttpContext context)
        {
            Console.WriteLine(">>>> Executing Query: " + context.Request.Path.Value);

            if (context.Request.Path.StartsWithSegments("/products"))
            {
                Guid?brand = null;
                Guid temp;
                if (Guid.TryParse(context.Request.Query["brand"], out temp))
                {
                    brand = temp;
                }

                ProductsQry qry = new ProductsQry()
                {
                    Name     = context.Request.Query["name"].FirstOrDefault() ?? null,
                    Category = context.Request.Query["category"].FirstOrDefault() ?? null,
                    Brand    = brand
                };

                var data = _handler.Handle(qry);

                context.Response.StatusCode = 200;
                context.Response.WriteAsync(JsonConvert.SerializeObject(data));
            }
            else if (context.Request.Path.StartsWithSegments("/product"))
            {
                Guid temp;
                if (Guid.TryParse(context.Request.Query["id"], out temp))
                {
                    ProductQry qry = new ProductQry()
                    {
                        Id = temp
                    };
                    var data = _handler.Handle(qry);
                    context.Response.StatusCode = 200;
                    context.Response.WriteAsync(JsonConvert.SerializeObject(data));
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
            }
            else if (context.Request.Path.StartsWithSegments("/brands"))
            {
                var data = _handler.Handle(new BrandQry());
                context.Response.StatusCode = 200;
                context.Response.WriteAsync(JsonConvert.SerializeObject(data));
            }
            else if (context.Request.Path.StartsWithSegments("/categories"))
            {
                var data = _handler.Handle(new CategoryQry());
                context.Response.StatusCode = 200;
                context.Response.WriteAsync(JsonConvert.SerializeObject(data));
            }
        }
        // 通过型号返回产品
        public JsonResult GetProduct(string db, string pNo, string flag)
        {
            var jsonResult = new JsonResult();

            jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            if (String.IsNullOrEmpty(pNo))
            {//
                return(jsonResult);
            }
            using (kw_m01Context kw_m01 = new kw_m01Context())
            {
                v_product product = kw_m01.v_product.Find(db, pNo);
                if (product == null)
                {
                    return(jsonResult);
                }

                var attrItem = kw_m01.v_attrItem.Find(db, product.cattrid);

                var colors = from s in kw_m01.v_prodcolor
                             where (s.db == db) && (s.CMTEID == pNo)
                             select new { text = s.cname, value = s.CCOLORID };

                decimal inventory = -99999;

                var store = kw_m01.gb_Store.Find(pNo);
                if (store != null)
                {
                    inventory = store.Inventory;
                }

                ProductQry productQry = new ProductQry();
                productQry.product   = product;
                productQry.attrItem  = attrItem;
                productQry.colors    = colors;
                productQry.cunit     = kw_m01.v_unit.Find(db, product.CUNITID).CNAME;
                productQry.inventory = inventory;

                string json = JsonConvert.SerializeObject(productQry);
                jsonResult.Data = json;
            }

            return(jsonResult);
        }
Beispiel #3
0
        public object Handle(ProductQry query)
        {
            var data = _repository.GetProduct(query.Id);

            return(data);
        }