/// <summary> /// This handled optional save to database with various validation and/or handlers /// Note: if it did save successfully to the database it alters the message /// </summary> /// <param name="db"></param> /// <param name="bizStatus"></param> /// <returns></returns> protected void SaveChangedIfRequiredAndNoErrors(DbContext db, IBizActionStatus bizStatus) { if (!bizStatus.HasErrors && RequiresSaveChanges) { bizStatus.CombineErrors(db.SaveChangesWithOptionalValidation( bizStatus.ShouldValidateSaveChanges(WrappedConfig.Config), WrappedConfig.Config)); WrappedConfig.Config.UpdateSuccessMessageOnGoodWrite(bizStatus, WrappedConfig.Config); } }
/// <summary> /// This handled optional save to database with various validation and/or handlers /// Note: if it did save successfully to the database it alters the message /// </summary> /// <param name="db"></param> /// <param name="bizStatus"></param> /// <returns></returns> protected async Task SaveChangedIfRequiredAndNoErrorsAsync(DbContext db, IBizActionStatus bizStatus) { if (!bizStatus.HasErrors && RequiresSaveChanges) { bizStatus.CombineErrors(await db.SaveChangesWithOptionalValidationAsync( bizStatus.ShouldValidateSaveChanges(WrappedConfig.Config), WrappedConfig.Config) .ConfigureAwait(false)); WrappedConfig.Config.UpdateSuccessMessageOnGoodWrite(bizStatus, WrappedConfig.Config); } }
/// <summary> /// This a) handled optional save to database and b) calling SetupSecondaryData if there are any errors /// It also makes sure that the runStatus is used at the primary return so that warnings are passed on. /// Note: if it did save successfully to the database it alters the message /// </summary> /// <param name="db"></param> /// <param name="bizStatus"></param> /// <returns></returns> protected void SaveChangedIfRequiredAndNoErrors(DbContext db, IBizActionStatus bizStatus) { if (!bizStatus.HasErrors && RequiresSaveChanges) { if (bizStatus.ValidateSaveChanges(Config)) { bizStatus.CombineErrors(db.SaveChangesWithValidation(Config)); } else { db.SaveChanges(); } Config.UpdateSuccessMessageOnGoodWrite(bizStatus, Config); } }
/// <summary> /// This a) handled optional save to database and b) calling SetupSecondaryData if there are any errors /// It also makes sure that the runStatus is used at the primary return so that warnings are passed on. /// Note: if it did save successfully to the database it alters the message /// </summary> /// <param name="db"></param> /// <param name="bizStatus"></param> /// <returns></returns> protected async Task SaveChangedIfRequiredAndNoErrorsAsync(DbContext db, IBizActionStatus bizStatus) { if (!bizStatus.HasErrors && RequiresSaveChanges) { if (bizStatus.ValidateSaveChanges(Config)) { bizStatus.CombineErrors(await db.SaveChangesWithValidationAsync(Config)); } else { await db.SaveChangesAsync().ConfigureAwait(false); } Config.UpdateSuccessMessageOnGoodWrite(bizStatus, Config); } }