Advertisement
Guest User

repo

a guest
Aug 31st, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using CoderCamps;
  2. using Day11.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7.  
  8. namespace Day11.Services
  9. {
  10. public class RecipeService
  11. {
  12. private IGenericRepository _repo;
  13.  
  14. public RecipeService(IGenericRepository repo)
  15. {
  16. _repo = repo;
  17. }
  18.  
  19. public IList<Recipe> ListRecipes()
  20. {
  21. return _repo.Query<Recipe>().ToList();
  22. }
  23.  
  24. public Recipe FindRecipe(int id)
  25. {
  26. return _repo.Find<Recipe>(id);
  27. }
  28.  
  29. public void CreateRecipe(Recipe recipe)
  30. {
  31. _repo.Add<Recipe>(recipe);
  32. _repo.SaveChanges();
  33. }
  34.  
  35. public void EditRecipe(Recipe recipe)
  36. {
  37. var original = this.FindRecipe(recipe.Id);
  38. original.Title = recipe.Title;
  39. original.DifficultyLevel = recipe.DifficultyLevel;
  40. _repo.SaveChanges();
  41. }
  42.  
  43. public void DeleteRecipe(int id)
  44. {
  45. _repo.Delete<Recipe>(id);
  46. _repo.SaveChanges();
  47. }
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement