Esempio n. 1
0
        public IQueryable <GolfCourse> Search(string name = null, string rank = null)
        {
            // query the database for golf course name that contain the search term

            var db = new GolfCourseContext();

            var results = db
                          .GolfCourse
                          .AsQueryable();

            // .Where(course =>
            //     course.Name.ToLower().Contains(name.ToLower())
            //     &&
            //     course.Rank.ToLower().Contains(rank.ToLower())
            //     );
            if (name != null)
            {
                results = results
                          .Where(course => course.Name.ToLower().Contains(name.ToLower()));
            }

            if (rank != null)
            {
                results = results
                          .Where(course => course.Rank.ToLower().Contains(rank.ToLower()));
            }

            return(results);
        }
        public ActionResult <GolfCourse> Post([FromBody] GolfCourse golfCourse)
        {
            // add to my databse
            var db = new GolfCourseContext();

            db.GolfCourse.Add(golfCourse);
            db.SaveChanges();
            // return the newly created golf course
            return(golfCourse);
        }
        public ActionResult Delete(int id)
        {
            // Remove the item from the database
            var db     = new GolfCourseContext();
            var course = db.GolfCourse.FirstOrDefault(c => c.Id == id);

            if (course == null)
            {
                return(NotFound());
            }
            db.GolfCourse.Remove(course);
            // Save the changes
            db.SaveChanges();
            // return ????
            return(Ok());
        }
        public ActionResult <GolfCourse> Put([FromRoute] int id, [FromBody] GolfCourse updatedData)
        {
            // TODO: The actual update
            var db         = new GolfCourseContext();
            var golfCourse = db.GolfCourse.FirstOrDefault(course => course.Id == id);

            golfCourse.Location      = updatedData.Location;
            golfCourse.Name          = updatedData.Name;
            golfCourse.NumberOfHoles = updatedData.NumberOfHoles;
            golfCourse.Rank          = updatedData.Rank;
            golfCourse.TotalYards    = updatedData.TotalYards;
            golfCourse.Par           = updatedData.Par;

            db.SaveChanges();

            return(golfCourse);
        }
Esempio n. 5
0
 public ReviewRepository(GolfCourseContext db)
 {
     this.db = db;
 }
 public GolfCourseRepositoryTests()
 {
     db = new GolfCourseContext();
     db.Database.BeginTransaction();
     underTest = new GolfCourseRepository(db);
 }
Esempio n. 7
0
 public GolfCourseRepository(GolfCourseContext db)
 {
     this.db = db;
 }
        public IEnumerable <GolfCourse> GetByWoozal(string zebra)
        {
            var db = new GolfCourseContext();

            return(db.GolfCourse.Where(w => w.Location.ToLower() == zebra.ToLower()));
        }
        public ActionResult <IEnumerable <GolfCourse> > Get()
        {
            var db = new GolfCourseContext();

            return(db.GolfCourse);
        }