1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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<Restaurant, bool> where)
- {
- return dBContext.Restaurants.Where(where).FirstOrDefault();
- }
-
- public IEnumerable<Restaurant> 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();
- }
- }
- }
|