예제 #1
0
        public HttpResponseMessage index()
        {
            List <ProductofCategory> pc = new List <ProductofCategory>();

            using (MobileStoreServiceEntities data = new MobileStoreServiceEntities())
            {
                List <CATEGORY> lst_cat = new List <CATEGORY>();
                lst_cat = (from e in data.CATEGORies
                           select e).ToList();
                foreach (var item in lst_cat)
                {
                    ProductofCategory temp = new ProductofCategory();
                    temp.category = item;
                    int cat_id = temp.category.CATEGORY_ID;

                    List <PRODUCT> listProduct = new List <PRODUCT>();
                    temp.listProduct = (from e in data.PRODUCTs
                                        join f in data.PRODUCT_CATEGORY on e.PRODUCT_ID equals f.PRODUCT_ID
                                        where f.CATEGORY_ID == cat_id && e.DELETED == 0
                                        select e).Take(5).ToList();

                    pc.Add(temp);
                }
            }
            //string json = JsonConvert.SerializeObject(pc);
            return(CreateResponse(HttpStatusCode.OK, pc));
        }
        public HttpResponseMessage GetProductOfCategory(int id)
        {
            ProductofCategory kq       = new ProductofCategory();
            CATEGORY          cat      = new CATEGORY();
            CATEGORY          category = new CATEGORY();

            using (MobileStoreServiceEntities data = new MobileStoreServiceEntities())
            {
                kq.listProduct = (from e in data.PRODUCT_CATEGORY
                                  join f in data.PRODUCTs on e.PRODUCT_ID equals f.PRODUCT_ID
                                  where e.CATEGORY_ID == id && f.DELETED == 0
                                  select f).Take(10).ToList();

                kq.category = (from c in data.CATEGORies
                               where c.CATEGORY_ID == id
                               select c).FirstOrDefault();
            }

            //string json = JsonConvert.SerializeObject(listProduct);
            return(CreateResponse(HttpStatusCode.OK, kq));
        }