using EnVisage.Models; using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; namespace EnVisage.Code { public class FeeCalculationManager { private readonly EnVisageEntities _dbContext; private readonly bool _isContexLocal = false; public FeeCalculationManager(EnVisageEntities dbContext) { if (dbContext == null) { _dbContext = new EnVisageEntities(); _isContexLocal = true; } else { _dbContext = dbContext; } } public void Dispose() { if (_isContexLocal) _dbContext.Dispose(); } #region Public Methods /// /// Loads a Fee from the database. /// /// Unique identifier of the Fee_Calculation . /// Indicates that object will not be saved later in the code. Use false if you need to save an updated object. /// A object retrieved from database. public FeeCalculation Load(Guid? value, bool isReadOnly = true) { if (value == null || value == Guid.Empty) return new FeeCalculation(); return isReadOnly ? _dbContext.FeeCalculation.AsNoTracking().FirstOrDefault(t => t.Id == value) : _dbContext.FeeCalculation.Find(value); } public void Save(FeeCalculationModel model) { if (model == null) throw new ArgumentNullException("model"); #region Save Fee_Calculation data FeeCalculation dbObj = null; if (model.Id != Guid.Empty) dbObj = _dbContext.FeeCalculation.Find(model.Id); if (dbObj == null) { dbObj = new FeeCalculation { Id = Guid.NewGuid() }; } model.CopyTo(dbObj); if (model.Id == Guid.Empty) _dbContext.FeeCalculation.Add(dbObj); else _dbContext.Entry(dbObj).State = EntityState.Modified; #endregion if (_isContexLocal) _dbContext.SaveChanges(); } #endregion } }