using Microsoft.EntityFrameworkCore; using ProRestaurant.DBContexts; using ProRestaurant.Models.Restaurants; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace ProRestaurant.Repository.Restaurants { public class RestaurantRepository : IRestaurantRepository { private readonly DBContext dBContext; public RestaurantRepository(DBContext db) { dBContext = db; } public Restaurant GetRestaurant(Func where) { return dBContext.Restaurants.Where(where).FirstOrDefault(); } public IEnumerable GetUsers() { return dBContext.Restaurants.ToList(); } public void Insert(Restaurant restaurant) { dBContext.Add(restaurant); Save(); } public void Remove(Restaurant restaurant) { dBContext.Restaurants.Remove(restaurant); Save(); } public void Save() { dBContext.SaveChanges(); } public void Update(Restaurant restaurant) { dBContext.Entry(restaurant).State = EntityState.Modified; Save(); } } }