Example #1
0
        public JsonResult List(int page, int rp, string qtype, string letter_pressed, string query)
        {
            using (var db = new EntContext())
            {
                if (letter_pressed == "ALL")
                {
                    letter_pressed = "";
                }

                Func <IQueryable <Customer> > CustomerFiltered = () =>
                                                                 db.Customers
                                                                 .Where(x =>
                                                                        (
                                                                            (
                                                                                !string.IsNullOrEmpty(letter_pressed) &&
                                                                                x.CompanyName.StartsWith(letter_pressed)
                                                                            )
                                                                            ||
                                                                            string.IsNullOrEmpty(letter_pressed)
                                                                        )
                                                                        &&
                                                                        (
                                                                            (
                                                                                !string.IsNullOrEmpty(query)
                                                                                &&
                                                                                (
                                                                                    (qtype == "CompanyName" && x.CompanyName.Contains(query))
                                                                                    ||
                                                                                    (qtype == "ContactName" && x.ContactName.Contains(query))
                                                                                    ||
                                                                                    (qtype == "ContactTitle" && x.ContactTitle.Contains(query))
                                                                                )
                                                                            )
                                                                            ||
                                                                            string.IsNullOrEmpty(query)
                                                                        )
                                                                        );


                return(Json(
                           new
                {
                    page = page,
                    total = CustomerFiltered().Count(),
                    rows =
                        CustomerFiltered()
                        .OrderBy(x => x.CompanyName)
                        .LimitAndOffset(pageSize: rp, pageOffset: page)
                        .ToList()
                        .Select(x =>
                                new
                    {
                        id = x.CustomerID,
                        cell = new string[] { x.CompanyName, x.ContactName, x.ContactTitle }
                    })
                }));
            } //using
        }     //List
 public MovieController()
 {
     _context = new EntContext();
 }
Example #3
0
        //Dictionary<int, Customer> customers = new Dictionary<int, Customer>
        //{
        //    {1, new Customer{ name = "John Smith" , id = 1}},
        //    {2, new Customer{ name = "Peter Maged" , id = 2}},
        //    {3, new Customer{ name = "Philip Fry" , id = 3}}
        //};

        public CustomerController()
        {
            _context = new EntContext();
        }
Example #4
0
 public HomeController(EntContext context)
 {
     db = context;
 }