API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PaymentRepository.cs 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Microsoft.EntityFrameworkCore;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnivateProperties_API.Context;
  6. using UnivateProperties_API.Model.Financial;
  7. namespace UnivateProperties_API.Repository.Financial
  8. {
  9. public class PaymentRepository : IRepository<Payment>
  10. {
  11. private readonly DataContext _dbContext;
  12. public PaymentRepository(DataContext dbContext)
  13. {
  14. _dbContext = dbContext;
  15. }
  16. public List<Payment> Get(Func<Payment, bool> where)
  17. {
  18. return _dbContext.Payments.Where(where).ToList();
  19. }
  20. public List<Payment> GetAll()
  21. {
  22. return _dbContext.Payments.OrderByDescending(p => p.Created).ToList();
  23. }
  24. public Payment GetDetailed(Func<Payment, bool> first)
  25. {
  26. var item = _dbContext.Payments.FirstOrDefault(first);
  27. return item;
  28. }
  29. public List<Payment> GetDetailedAll()
  30. {
  31. return GetAll();
  32. }
  33. public void Insert(Payment item)
  34. {
  35. _dbContext.Add(item);
  36. Save();
  37. }
  38. public void Insert(IEnumerable<Payment> items)
  39. {
  40. foreach(var item in items)
  41. {
  42. _dbContext.Add(item);
  43. }
  44. Save();
  45. }
  46. public int NewId()
  47. {
  48. throw new NotImplementedException();
  49. }
  50. public void Remove(Payment item)
  51. {
  52. var i = _dbContext.Payments.Find(item);
  53. _dbContext.Payments.Remove(i);
  54. Save();
  55. }
  56. public void Remove(IEnumerable<Payment> items)
  57. {
  58. foreach (var item in items)
  59. {
  60. var i = _dbContext.Payments.Find(item);
  61. _dbContext.Payments.Remove(i);
  62. }
  63. Save();
  64. }
  65. public void RemoveAtId(int item)
  66. {
  67. var i = _dbContext.Payments.Find(item);
  68. _dbContext.Payments.Remove(i);
  69. Save();
  70. }
  71. public void Save()
  72. {
  73. _dbContext.SaveChanges();
  74. }
  75. public void Update(Payment item)
  76. {
  77. _dbContext.Entry(item).State = EntityState.Modified;
  78. Save();
  79. }
  80. }
  81. }