コード例 #1
0
        public static void Do <T>(this ITestTaskDbContext context, Action <DbSet <T> > act, Boolean shouldSave = false)
            where T : class
        {
            act(context.Set <T>());
            if (!shouldSave)
            {
                return;
            }

            context.SaveChanges();
            return;
        }
コード例 #2
0
        public static async Task Do <T>(this ITestTaskDbContext context, Func <DbSet <T>, Task> act, Boolean shouldSave = false)
            where T : class
        {
            await act(context.Set <T>());

            if (!shouldSave)
            {
                return;
            }

            await context.SaveChangesAsync();

            return;
        }
コード例 #3
0
        public static async Task <R> DoWithResult <T, R>(this ITestTaskDbContext context, Func <DbSet <T>, Task <R> > act, Boolean shouldSave = false)
            where T : class
        {
            var res = await act(context.Set <T>());

            if (!shouldSave)
            {
                return(res);
            }

            await context.SaveChangesAsync();

            return(res);
        }
コード例 #4
0
 public OrderDataService(ITestTaskDbContext dbContext, ILogger <IOrderDataService> logger)
 {
     context     = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }