API
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ListingRepository.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.Financial;
  7. namespace UnivateProperties_API.Repository.Financial
  8. {
  9. public interface IListingRepository
  10. {
  11. ListingFee insertListingFee(ListingFee fee);
  12. ListingFee GetListingFee();
  13. }
  14. public class ListingRepository : IListingRepository
  15. {
  16. private readonly DataContext _dbContext;
  17. public ListingRepository(DataContext db)
  18. {
  19. _dbContext = db;
  20. }
  21. public ListingFee insertListingFee(ListingFee fee)
  22. {
  23. var hasFee = _dbContext.ListingFees.FirstOrDefault();
  24. if (fee != null)
  25. {
  26. if (hasFee == null)
  27. {
  28. _dbContext.ListingFees.Add(fee);
  29. _dbContext.SaveChanges();
  30. return fee;
  31. }
  32. else
  33. {
  34. fee.Id = 1;
  35. hasFee.Amount = fee.Amount;
  36. _dbContext.ListingFees.Update(hasFee);
  37. _dbContext.SaveChanges();
  38. return fee;
  39. }
  40. }
  41. else
  42. {
  43. return null;
  44. }
  45. }
  46. public ListingFee GetListingFee()
  47. {
  48. return _dbContext.ListingFees.FirstOrDefault();
  49. }
  50. }
  51. }