Esempio n. 1
0
        // GET: api/ProdMfg/5
        // The parameter for this method must be 'id'. It can be
        // a string or a number.
        public IHttpActionResult Get(string id)
        {
            // Get Manufacturer object by id.
            string mfg = id;
            JB_FoodStoreEntities db           = new JB_FoodStoreEntities();
            Manufacturer         manufacturer = db.Manufacturers.Where(m => m.mfg == mfg)
                                                .FirstOrDefault();

            // Create JArray of products from anonymous type List.
            var products = db.Products.Where(m => m.mfg == id)
                           .Select(p => new { productID = p.productID, price = p.price })
                           .ToList();
            JArray prodArray = (JArray)JToken.FromObject(products);

            // Create final JSON object.
            dynamic obj = new JObject();

            obj.mfg         = manufacturer.mfg;
            obj.mfgDiscount = manufacturer.mfgDiscount;
            obj.products    = prodArray;

            if (obj == null)
            {
                return(NotFound());
            }
            return(Ok(obj));
        }
        // GET: api/Products
        public IQueryable <Product> GetProducts()
        {
            JB_FoodStoreEntities context = new JB_FoodStoreEntities();

            context.Configuration.LazyLoadingEnabled = false;
            return(context.Products);
        }
Esempio n. 3
0
        // GET: api/ProdMfg/5
        // The parameter for this method must be 'id'. It can be
        // a string or a number.
        public IHttpActionResult Get(string id)
        {
            // Get Manufacturer object by id.
            string mfg = id;
            JB_FoodStoreEntities db = new JB_FoodStoreEntities();
            Manufacturer manufacturer = db.Manufacturers.Where(m => m.mfg == mfg)
                                            .FirstOrDefault();

            // Create JArray of products from anonymous type List.
            var products = db.Products.Where(m => m.mfg == id)
                                .Select(p => new { productID = p.productID, price = p.price })
                                .ToList();
            JArray prodArray = (JArray)JToken.FromObject(products);

            // Create final JSON object.
            dynamic obj = new JObject();
            obj.mfg = manufacturer.mfg;
            obj.mfgDiscount = manufacturer.mfgDiscount;
            obj.products = prodArray;

            if (obj == null)
            {
                return NotFound();
            }
            return Ok(obj);
        }
 public async Task<List<ManufacturerVM>> GetAll()
 {
     JB_FoodStoreEntities db = new JB_FoodStoreEntities();
     List<ManufacturerVM> response = new List<ManufacturerVM>();
     response = await db.Manufacturers.Select(m => new ManufacturerVM { mfg = m.mfg, mfgDiscount = (decimal)m.mfgDiscount }).ToListAsync();
     return response;
 }
        public IEnumerable<Product> GetProducts(string searchString, string sortOrder)
        {
            JB_FoodStoreEntities context = new JB_FoodStoreEntities();
            IEnumerable<Product> products = from s in context.Products
                                            select s;

            products = FilterProducts(products, searchString);
            products = SortProducts(products, sortOrder);

            return products;
        }
        public IHttpActionResult GetProduct(int id)
        {
            JB_FoodStoreEntities context = new JB_FoodStoreEntities();

            context.Configuration.LazyLoadingEnabled = false;

            Product product = context.Products.Find(id);

            if (product == null)
            {
                return(NotFound());
            }

            return(Ok(product));
        }
        public ActionResult Index(string currentFilter, string sortOrder, string searchString, int? page)
        {
            JB_FoodStoreEntities context = new JB_FoodStoreEntities();

            if (searchString != null)
                page = 1;
            else
                searchString = currentFilter;


            FoodRespository productRepo = new FoodRespository();
            IEnumerable<Product> products = productRepo.GetProducts(searchString, sortOrder);

            // Store current sort filter parameter.
            ViewBag.CurrentFilter = searchString;
            ViewBag.CurrentSort = sortOrder;

            // Provide toggle option for name sort.
            if (String.IsNullOrEmpty(sortOrder))
                ViewBag.NameSortParm = FoodRespository.NAME;
            else
                ViewBag.NameSortParm = "";

            // Provide toggle  optionfor date sort.
            if (sortOrder == FoodRespository.MFGDISCOUNT)
                ViewBag.DateSortParm = FoodRespository.MFG_DESC;
            else
                ViewBag.DateSortParm = FoodRespository.MFGDISCOUNT;


            const int PAGE_SIZE = 2;
            int pageNumber = (page ?? 1);
            // Truncate results to fit in the view provided.
            products = products.ToPagedList(pageNumber, PAGE_SIZE);
            return View(products);
        }
 public ManufacturerRepository(JB_FoodStoreEntities context)
 {
     this.context = context;
 }
 public ProductRepository(JB_FoodStoreEntities context)
 {
     this.context = context;
 }