1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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();
- }
- }
- }
|