Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using CoderCamps;
- using Day11.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace Day11.Services
- {
- public class RecipeService
- {
- private IGenericRepository _repo;
- public RecipeService(IGenericRepository repo)
- {
- _repo = repo;
- }
- public IList<Recipe> ListRecipes()
- {
- return _repo.Query<Recipe>().ToList();
- }
- public Recipe FindRecipe(int id)
- {
- return _repo.Find<Recipe>(id);
- }
- public void CreateRecipe(Recipe recipe)
- {
- _repo.Add<Recipe>(recipe);
- _repo.SaveChanges();
- }
- public void EditRecipe(Recipe recipe)
- {
- var original = this.FindRecipe(recipe.Id);
- original.Title = recipe.Title;
- original.DifficultyLevel = recipe.DifficultyLevel;
- _repo.SaveChanges();
- }
- public void DeleteRecipe(int id)
- {
- _repo.Delete<Recipe>(id);
- _repo.SaveChanges();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement