Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

RestaurantRepository.cs 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Microsoft.EntityFrameworkCore;
  2. using ProRestaurant.Classes;
  3. using ProRestaurant.Containers;
  4. using ProRestaurant.DBContexts;
  5. using ProRestaurant.Models.Restaurants;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. namespace ProRestaurant.Repository.Restaurants
  10. {
  11. public class RestaurantRepository : IRestaurantRepository
  12. {
  13. private readonly DBContext dBContext;
  14. public RestaurantRepository(DBContext db)
  15. {
  16. dBContext = db;
  17. }
  18. public Restaurant GetRestaurant(Func<Restaurant, bool> where)
  19. {
  20. return dBContext.Restaurants.Where(where).FirstOrDefault();
  21. }
  22. public IEnumerable<Restaurant> GetRestaurants()
  23. {
  24. return dBContext.Restaurants.ToList();
  25. }
  26. public List<RestaurantCard> GetSearch()
  27. {
  28. var restaurants = dBContext.Restaurants.ToList();
  29. List<RestaurantCard> cards = new List<RestaurantCard>();
  30. foreach (var rest in restaurants)
  31. {
  32. var card = new RestaurantCard
  33. {
  34. Id = rest.Id,
  35. Name = rest.Name,
  36. Suburb = rest.Suburb,
  37. SubText = rest.Categories,
  38. DeliveryFee = string.Format("{0:C}", rest.DeliveryFee),
  39. DeliveryTime = rest.DeliveryTime
  40. };
  41. if (!rest.Logo.Contains("data:image"))
  42. card.Logo = ImageFormatter.ImageToBase64(rest.Logo);
  43. else
  44. card.Logo = rest.Logo;
  45. cards.Add(card);
  46. }
  47. return cards;
  48. }
  49. public void Insert(Restaurant restaurant)
  50. {
  51. dBContext.Add(restaurant);
  52. Save();
  53. }
  54. public void Remove(Restaurant restaurant)
  55. {
  56. dBContext.Restaurants.Remove(restaurant);
  57. Save();
  58. }
  59. public void Save()
  60. {
  61. dBContext.SaveChanges();
  62. }
  63. public void Update(Restaurant restaurant)
  64. {
  65. dBContext.Entry(restaurant).State = EntityState.Modified;
  66. Save();
  67. }
  68. }
  69. }