public PartialViewResult Favorite(int routeID, bool makeFavorite) { FavoriteModel fm = new FavoriteModel((Guid)Membership.GetUser().ProviderUserKey, routeID); if (makeFavorite) FavoriteModel.insertFavorite(fm); else FavoriteModel.deleteFavorite(fm); RouteModel rm = new RouteModel(routeID); return PartialView("Routes/_ListRoutesElement", rm); }
public static void deleteFavorite(FavoriteModel fm) { Favorite favorite = (from r in _db.Favorites where r.Route_ID == fm.routeID && r.User_ID == fm.userID select r).SingleOrDefault(); if (favorite != null) { _db.Favorites.DeleteOnSubmit(favorite); _db.SubmitChanges(); } }
public static void insertFavorite(FavoriteModel fm) { // Check if already favored Favorite favorite = (from f in _db.Favorites where f.Route_ID == fm.routeID && f.User_ID == fm.userID select f).SingleOrDefault(); if (favorite == null) { favorite = new Favorite(); favorite.User_ID = fm.userID; favorite.Route_ID = fm.routeID; _db.Favorites.InsertOnSubmit(favorite); _db.SubmitChanges(); // Create event that this route has been favored RouteFavoredEvent rfe = new RouteFavoredEvent(favorite); rfe.save(); } }