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.

SMTPHostRepository.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.Communication;
  7. namespace UnivateProperties_API.Repository.Communication
  8. {
  9. public class SMTPHostRepository : IRepository<SMTPHost>
  10. {
  11. private readonly DataContext _dbContext;
  12. public SMTPHostRepository(DataContext dbContext)
  13. {
  14. _dbContext = dbContext;
  15. }
  16. public List<SMTPHost> Get(Func<SMTPHost, bool> where)
  17. {
  18. return _dbContext.Hosts.Where(where).ToList();
  19. }
  20. public List<SMTPHost> GetAll()
  21. {
  22. return _dbContext.Hosts.ToList();
  23. }
  24. public SMTPHost GetDetailed(Func<SMTPHost, bool> first)
  25. {
  26. return _dbContext.Hosts.FirstOrDefault(first);
  27. }
  28. public List<SMTPHost> GetDetailedAll()
  29. {
  30. return GetAll();
  31. }
  32. public void Insert(SMTPHost item)
  33. {
  34. _dbContext.Add(item);
  35. Save();
  36. }
  37. public void Insert(IEnumerable<SMTPHost> items)
  38. {
  39. foreach (var item in items)
  40. {
  41. _dbContext.Add(item);
  42. }
  43. Save();
  44. }
  45. public void Remove(SMTPHost item)
  46. {
  47. var i = _dbContext.Hosts.Find(item);
  48. _dbContext.Hosts.Remove(i);
  49. Save();
  50. }
  51. public void Remove(IEnumerable<SMTPHost> items)
  52. {
  53. foreach (var item in items)
  54. {
  55. SMTPHost i = _dbContext.Hosts.Find(item);
  56. _dbContext.Hosts.Remove(i);
  57. }
  58. Save();
  59. }
  60. public void RemoveAtId(int item)
  61. {
  62. var i = _dbContext.Hosts.Find(item);
  63. _dbContext.Hosts.Remove(i);
  64. Save();
  65. }
  66. public void Update(SMTPHost item)
  67. {
  68. _dbContext.Entry(item).State = EntityState.Modified;
  69. Save();
  70. }
  71. public void Save()
  72. {
  73. _dbContext.SaveChanges();
  74. }
  75. }
  76. }