using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using UnivateProperties_API.Context; using UnivateProperties_API.Model.Misc; namespace UnivateProperties_API.Repository.Misc { public interface ITCRepository { void SetTC(TC terms); TC GetTC(); } public class TCRepository : ITCRepository { private readonly DataContext _dbContext; public TCRepository(DataContext db) { _dbContext = db; } public void SetTC(TC terms) { var pulledTerms = _dbContext.TermsConditions.FirstOrDefault(); if (terms != null) { if (pulledTerms == null) { _dbContext.TermsConditions.Add(terms); _dbContext.SaveChanges(); } else { pulledTerms.TermsConditions = terms.TermsConditions; pulledTerms.Version = terms.Version; _dbContext.TermsConditions.Update(pulledTerms); _dbContext.SaveChanges(); } } } public TC GetTC() { return _dbContext.TermsConditions.FirstOrDefault(); } } }