API
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ListingRepository.cs 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. _dbContext.ListingFees.Update(fee);
  36. _dbContext.SaveChanges();
  37. return fee;
  38. }
  39. }
  40. else
  41. {
  42. return null;
  43. }
  44. }
  45. public ListingFee GetListingFee()
  46. {
  47. return _dbContext.ListingFees.FirstOrDefault();
  48. }
  49. }
  50. }