public ActionResult Edit(PLC.Review rev, Nullable <int> rID) { PLC.Restaurant rest = new PLC.Restaurant(); try { if (func == null) { func = new PLC.Functionality(); } rest = func.GetRestaurant(rev.RestaurantID); if (isValid(rev)) { func.UpdateReview(rev.RestaurantID, rev); return(RedirectToAction("Details", "Restaurant", rest)); } return(RedirectToAction("Details", "Restaurant", rest)); } catch (Exception ex) { logger.Error(ex.Message); return(RedirectToAction("Index", "Restaurant", rest)); } }
// GET: Restaurant/Details/5 public ActionResult Details(PLC.Restaurant rest) { if (isValid(rest)) { if (func == null) { func = new PLC.Functionality(); } // Grab all of the selected Restaurant's reviews var reviews = func.GetReviews(rest.RestaurantID); // Add the RestaurantID to each of the review objects for future reference foreach (var review in reviews) { review.RestaurantID = rest.RestaurantID; } if (reviews.Count == 0) { reviews.Add(new PLC.Review() { RestaurantID = rest.RestaurantID }); } return(View(reviews)); } else { return(RedirectToAction("Index")); } }
public ActionResult Create(PLC.Review review, int restID) { try { if (isValid(review)) { if (func == null) { func = new PLC.Functionality(); } func.AddReview(restID, review); var rest = func.GetRestaurant(restID); return(RedirectToAction("Details", "Restaurant", rest)); } return(RedirectToAction("Index", "Restaurant")); } catch (Exception ex) { logger.Error(ex.Message); return(RedirectToAction("Index", "Restaurant")); } }
// GET: Review/Delete/5 public ActionResult Delete(PLC.Review rev) { if (func == null) { func = new PLC.Functionality(); } func.DeleteReview(rev.RestaurantID, rev.ReviewID); var rest = func.GetRestaurant(rev.RestaurantID); return(RedirectToAction("Details", "Restaurant", rest)); }
public void TestEdit() { RestaurantController rc = new RestaurantController(); PLC.Functionality func = new PLC.Functionality(); var rest = func.GetRestaurant(1);// grab Carl's Jr. string expected = rest.ToString(); var action = rc.Edit(1) as ViewResult; var r = (PLC.Restaurant)action.Model; string actual = r.ToString(); Assert.AreEqual(expected, actual); }
public void TestReviewDetails() { ReviewController rc = new ReviewController(); PLC.Functionality func = new PLC.Functionality(); var reviews = func.GetReviews(1); // Grab Carl's Jr. reviews string expected = "zschiesterl11"; // Reviewer that gave Carl's Jr. a rating of 4 var action = rc.Edit(reviews[reviews.Count - 2]) as ViewResult; var actual = ((PLC.Review)action.Model).Author; // The actual reviewer that was passed to the view Assert.AreEqual(expected, actual); }
public void TestDetails() { RestaurantController rc = new RestaurantController(); PLC.Functionality func = new PLC.Functionality(); var rest = func.GetRestaurant(1); int expected = 8; // Carl's Jr. Should have 8 reviews var action = rc.Details(rest) as ViewResult; var model = (List <PLC.Review>)action.Model; int actual = model.Count; Assert.AreEqual(expected, actual); }
// GET: Restaurant/Delete/5 public ActionResult Delete(PLC.Restaurant rest) { try { if (func == null) { func = new PLC.Functionality(); } func.DeleteRestaurant(rest); } catch (Exception ex) { logger.Error(ex.Message); } return(RedirectToAction("Index")); }
// GET: Restaurant/Edit/5 public ActionResult Edit(int restID) { PLC.Restaurant rest = new PLC.Restaurant(); try { if (func == null) { func = new PLC.Functionality(); } rest = func.GetRestaurant(restID); } catch (Exception ex) { logger.Error(ex.Message); } return(View(rest)); }
public ActionResult TopThree() { List <PLC.Restaurant> restaurants = new List <PLC.Restaurant>(); try { if (func == null) { func = new PLC.Functionality(); } restaurants = func.TopThreeRestaurants(); } catch (Exception ex) { logger.Error(ex.Message); } return(View("Index", restaurants)); }
public ActionResult Search(FormCollection collection) { List <PLC.Restaurant> restaurants = new List <PLC.Restaurant>(); try { if (func == null) { func = new PLC.Functionality(); } restaurants = func.SearchRestaurantsByName(collection[0]); } catch (Exception ex) { logger.Error(ex.Message); } return(View("Index", restaurants)); }
// GET: Restaurants public ActionResult Index() { List <PLC.Restaurant> restaurants = new List <PLC.Restaurant>(); try { if (func == null) { func = new PLC.Functionality(); } // Grab all of the restaurants from the database restaurants = func.AllRestaurants(); return(View(restaurants)); } catch (Exception ex) { logger.Error(ex.Message); return(View("Error", ex)); } }
public ActionResult Create(PLC.Restaurant Model) { try { if (isValid(Model)) { // Add the Restaurant into the database if (func == null) { func = new PLC.Functionality(); } func.AddRestaurant(Model); } return(RedirectToAction("Index")); } catch (Exception ex) { return(View("Error", ex)); } }
public ActionResult Sort(bool asc) { List <PLC.Restaurant> restaurants = new List <PLC.Restaurant>(); try { if (func == null) { func = new PLC.Functionality(); } restaurants = func.AllRestaurants(); restaurants.Sort(); if (!asc) { restaurants.Reverse(); } } catch (Exception ex) { logger.Error(ex.Message); } return(View("Index", restaurants)); }
public ActionResult Edit(PLC.Restaurant rest, int restID) { try { if (isValid(rest)) { if (func == null) { func = new PLC.Functionality(); } // Make that an Edit did take place var original = func.GetRestaurant(restID); if (original.Equals(rest)) { // It's the same so just go back to the Index without updating the database return(RedirectToAction("Index")); } else { // The Restaurant's details have been changed so we need to update the database rest.RestaurantID = restID; // Making sure the ID is the right one func.UpdateRestaurant(rest); return(RedirectToAction("Index")); } } else { return(RedirectToAction("Index")); } } catch (Exception ex) { return(View("Error", ex)); } }