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.

TCRepository.cs 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using UnivateProperties_API.Context;
  6. using UnivateProperties_API.Model.Misc;
  7. namespace UnivateProperties_API.Repository.Misc
  8. {
  9. public interface ITCRepository
  10. {
  11. void SetTC(TC terms);
  12. TC GetTC();
  13. }
  14. public class TCRepository : ITCRepository
  15. {
  16. private readonly DataContext _dbContext;
  17. public TCRepository(DataContext db)
  18. {
  19. _dbContext = db;
  20. }
  21. public void SetTC(TC terms)
  22. {
  23. var pulledTerms = _dbContext.TermsConditions.FirstOrDefault();
  24. if (terms != null)
  25. {
  26. if (pulledTerms == null)
  27. {
  28. _dbContext.TermsConditions.Add(terms);
  29. _dbContext.SaveChanges();
  30. }
  31. else
  32. {
  33. pulledTerms.TermsConditions = terms.TermsConditions;
  34. pulledTerms.Version = terms.Version;
  35. _dbContext.TermsConditions.Update(pulledTerms);
  36. _dbContext.SaveChanges();
  37. }
  38. }
  39. }
  40. public TC GetTC()
  41. {
  42. return _dbContext.TermsConditions.FirstOrDefault();
  43. }
  44. }
  45. }