Example #1
0
        public IActionResult Get()
        {
            if (Request != null && Request.Query.ContainsKey("unused"))
            {
                bool unused = Request.Query["unused"].ToString() == "y";
                if (unused)
                {
                    return(Ok(new ProductsRepo().GetUnused()));
                }
            }

            //filter and sort args
            bool active = false;

            if (Request != null && Request.Query.ContainsKey("active"))
            {
                active = Request.Query["active"].ToString() == "y";
            }

            bool sort = false;

            if (Request != null && Request.Query.ContainsKey("sbh"))
            {
                sort = Request.Query["sbh"].ToString() == "true";
            }

            List <Product> newProds = new ProductsRepo().GetAll(active ? 120 : -1);

            try
            {
                if (sort)
                {
                    newProds.Sort();
                }
                else
                {
                    newProds.Sort(new Sorter());
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            return(Ok(newProds));
        }