/// <summary> /// Called when an edit operation is aborted /// </summary> public void CancelEdit() { _editCount--; if (_editCount > 0 || _editContext == null) { return; } // End context _editContext.Dispose(); _editContext = null; // Notify event waiters OnEditconcelled(EventArgs.Empty); }
/// <summary> /// Called before an edit operation begins on this object /// </summary> public void BeginEdit() { // If no db context is started, start one now if (_editContext == null) { // Notify event waiters OnEditBeginning(EventArgs.Empty); // Begin a db context _editContext = new SoCashDbContext(); // Attach this entry to the context - initially unchanged, but changes will be tracked from here out _editContext.Entry(this).State = EntityState.Unchanged; // Notify event waiters OnEditBegun(EventArgs.Empty); } _editCount++; }
/// <summary> /// Called after an edit operation ends on this object /// </summary> public void EndEdit() { _editCount--; if (_editCount > 0 || _editContext == null) { return; } // Notify event waiters OnEditEnding(EventArgs.Empty); // Commit changes to database _editContext.SaveChanges(); // End context _editContext.Dispose(); _editContext = null; // Notify event waiters OnEditEnded(EventArgs.Empty); }
/// <summary> /// Allows mock framework to pass in a mock db context for testing /// </summary> /// <param name="dbContext">Alternate DB Context to use for service opperations</param> internal BaseService(SoCashDbContext dbContext) { DbContext = dbContext; }
/// <summary> /// No-argument constructor uses a real database context /// </summary> internal BaseService() { DbContext = new SoCashDbContext(); }
/// <summary> /// Allows mock framework to pass in a mock db context for testing /// </summary> /// <param name="dbContext">Alternate DB Context to use for service opperations</param> public DataService(SoCashDbContext dbContext) : base(dbContext) { }
/// <summary> /// Called when an edit operation is aborted /// </summary> public void CancelEdit() { _editCount--; if (_editCount > 0 || _editContext == null) return; // End context _editContext.Dispose(); _editContext = null; // Notify event waiters OnEditconcelled(EventArgs.Empty); }
/// <summary> /// Called after an edit operation ends on this object /// </summary> public void EndEdit() { _editCount--; if (_editCount > 0 || _editContext == null) return; // Notify event waiters OnEditEnding(EventArgs.Empty); // Commit changes to database _editContext.SaveChanges(); // End context _editContext.Dispose(); _editContext = null; // Notify event waiters OnEditEnded(EventArgs.Empty); }