예제 #1
0
        public static async Task <RedirectResult> SaveAndRedirectAsync <TModel, TIdentity, TUser>(
            this DapperCX <TIdentity, TUser> crudService, TModel model, Func <TModel, Exception, RedirectResult> redirect,
            ChangeTracker <TModel> changeTracker = null, Action <TModel> beforeSave             = null,
            Func <TModel, Task> onSuccess        = null, Action <TModel, Exception> onException = null) where TUser : IUserBase
        {
            beforeSave?.Invoke(model);

            try
            {
                var result = await crudService.SaveAsync(model, changeTracker);

                onSuccess?.Invoke(model);
                return(redirect.Invoke(model, null));
            }
            catch (Exception exc)
            {
                onException?.Invoke(model, exc);
                return(redirect.Invoke(model, exc));
            }
        }