Example #1
0
        public ActionResult Autocomplete(string term)
        {
            var model =
                _db.Query <Cow>()
                .Where(r => r.Name.StartsWith(term))
                .Take(10)
                .Select(r => new
            {
                label = r.Name
            });

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        //GET: Bulls/Calves/5
        public ActionResult Calves(int?id, int page = 1)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Bull bull = db.Bulls.Find(id);

            if (bull == null)
            {
                return(HttpNotFound());
            }
            string bullname = bull.Name;
            List <CalfListViewModel> listCalves = new List <CalfListViewModel>();

            listCalves =
                _db.Query <Cow>()
                .Where(r => r.Sire == bull.Name)
                .OrderByDescending(r => r.DOB)
                .Select(r => new CalfListViewModel
            {
                Id         = r.Id,
                ParentName = bullname,
                ParentSex  = "M",
                Name       = r.Name,
                DOB        = r.DOB,
                tagNumber  = r.tagNumber,
                Sex        = r.Sex,
                Status     = r.Status,
                Owner      = r.Owner,
                Dam        = r.Dam
            }).ToList();

            var model = listCalves.ToPagedList(page, 10);

            return(View(model));
        }