public void EnsureSeedDataExists() { if (Restaurants.Any()) { return; } var sampleRestaurants = new List <Restaurant> { new Restaurant { Name = "Scott's Pizza", Location = "Maryland", Cuisine = CuisineType.Italian }, new Restaurant { Name = "Joe's Mexican Restaurant", Location = "Texas", Cuisine = CuisineType.Mexican }, new Restaurant { Name = "Jeffrey's Lounge", Location = "Manitoba", Cuisine = CuisineType.Comfort }, new Restaurant { Name = "Clay Oven", Location = "Manitoba", Cuisine = CuisineType.Indian } }; Restaurants.AddRange(sampleRestaurants); SaveChanges(); }
public Restaurant(string name, User owner) { Id = Restaurants.Any() ? Restaurants.Last().Id + 1 : 0; Name = name; OwnerId = owner.Id; Rating = 0; }
public Vote Vote(int id) { string Username = HttpContext.Current.Request["LOGON_USER"]; if (!Restaurants.Any(i => i.ID == id)) { throw new Exception("No restaurant exists with that id."); } Restaurant Restaurant = Restaurants.First(i => i.ID == id); var Vote = new Vote(Restaurant, Username); if (this.Votes.Any(i => i.Username == Username && i.Timestamp >= DateTime.Today)) { throw new Exception("You cannot vote twice per day."); } Votes.Add(Vote); return(Vote); }