Пример #1
0
        public static async Task <RedirectResult> DeleteAndRedirectAsync <TModel, TIdentity, TUser>(
            this DapperCX <TIdentity, TUser> crudService, TIdentity id, Func <TModel, Exception, RedirectResult> redirect,
            Func <TModel, Task> onSuccess = null, Action <TModel, Exception> onException = null) where TUser : IUserBase
        {
            var model = await crudService.GetAsync <TModel>(id);

            try
            {
                await crudService.DeleteAsync <TModel>(id);

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