using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using UnivateProperties_API.Context; using UnivateProperties_API.Model.Financial; namespace UnivateProperties_API.Repository.Financial { public interface IListingRepository { ListingFee insertListingFee(ListingFee fee); ListingFee GetListingFee(); } public class ListingRepository : IListingRepository { private readonly DataContext _dbContext; public ListingRepository(DataContext db) { _dbContext = db; } public ListingFee insertListingFee(ListingFee fee) { var hasFee = _dbContext.ListingFees.FirstOrDefault(); if (fee != null) { if (hasFee == null) { _dbContext.ListingFees.Add(fee); _dbContext.SaveChanges(); return fee; } else { fee.Id = 1; hasFee.Amount = fee.Amount; _dbContext.ListingFees.Update(hasFee); _dbContext.SaveChanges(); return fee; } } else { return null; } } public ListingFee GetListingFee() { return _dbContext.ListingFees.FirstOrDefault(); } } }