Ejemplo n.º 1
0
        public ActionResult PostReview([FromRoute] int id)
        {
            var db      = new CoffeeShopFinderContext();
            var results = db.Reviews.Where(w => w.LocationId == id).OrderByDescending(o => o.CreatedAt);

            return(Ok(results));
        }
Ejemplo n.º 2
0
        public ActionResult GetALocation([FromRoute] int id)
        {
            var db = new CoffeeShopFinderContext();

            return(Ok(db.Locations
                      .Include(i => i.Franchise)
                      .SingleOrDefault(s => s.Id == id)));
        }
Ejemplo n.º 3
0
        public ActionResult PostReview([FromRoute] int id, [FromBody] Review review)
        {
            var db = new CoffeeShopFinderContext();

            review.LocationId = id;
            var userId = User.Claims.First(f => f.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;

            review.UserId = userId;
            db.Reviews.Add(review);
            db.SaveChanges();
            return(Ok(review));
        }
Ejemplo n.º 4
0
        public ActionResult GetAction([FromRoute] string brand)
        {
            var db      = new CoffeeShopFinderContext();
            var results = db.Franchises
                          .Include(i => i.Locations)
                          .FirstOrDefault(w => w.Brand.ToLower() == brand.ToLower());

            if (results == null)
            {
                return(NotFound(new { message = $"Brand {brand} was not found. Use the GET /franchises to get a list of brands" }));
            }
            return(Ok(results));
        }
Ejemplo n.º 5
0
        public ActionResult AddRating([FromRoute] int id, [FromBody] Rating rating)
        {
            var db = new CoffeeShopFinderContext();

            rating.LocationId = id;
            db.Ratings.Add(rating);
            db.SaveChanges();
            // update the average
            // sum the numbers, divide by lenght
            var average = db.Ratings.Average(a => a.Score);
            // update the location with the average
            var shop = db.Locations.SingleOrDefault(sh => sh.Id == id);

            shop.AverageRating = (float)average;
            db.SaveChanges();

            return(Ok(new { rating = average }));
        }
Ejemplo n.º 6
0
        public ActionResult GetUserReview([FromRoute] int id, [FromRoute] string userId)
        {
            // query the review table to get the firstordefault (f => f.locationId && f.userId )
            var db     = new CoffeeShopFinderContext();
            var review = db.Reviews.FirstOrDefault(f => f.LocationId == id && f.UserId == userId);

            // if (found)
            if (review != null)
            {
                return(Ok(new { wasFound = true, review }));
            }
            else
            {
                return(Ok(new { wasFound = false }));
            }
            // return that
            // else return a not found message
        }
Ejemplo n.º 7
0
        public ActionResult Get([FromQuery] String searchTerm)
        {
            var db = new CoffeeShopFinderContext();

            //connect to database v
            var results = db.Locations.Include(i => i.Franchise)
                          .Where(w =>
                                 w.Franchise.Brand.ToLower().Contains(searchTerm.ToLower()) ||
                                 w.City.ToLower().Contains(searchTerm.ToLower()) ||
                                 w.Zip.Contains(searchTerm)
                                 );



            // query for locations that have where brand/city/zip contains search term
            return(Ok(results));



            // return results
        }
Ejemplo n.º 8
0
        public ActionResult GetAction()
        {
            var db = new CoffeeShopFinderContext();

            return(Ok(db.Locations.Include(i => i.Franchise).OrderBy(o => o.Zip)));
        }