public async Task OnResourceExecutionAsync(ResourceExecutingContext before, ResourceExecutionDelegate next) { var modifying = false; if (before.ActionDescriptor is ControllerActionDescriptor action) { modifying = action.MethodInfo.GetCustomAttributes <DatabaseUpdateAttribute>().Any(); } if (modifying) { using (var handle = await access.Write()) { var after = await next(); var status = after.HttpContext.Response.StatusCode; if (status < 400) { await SaveChanges(handle); } } } else { using (await access.Read()) { await next(); } } }
private async Task <Email> Next() { using (await access.Read()) { var unsent = from mail in emails.Include(e => e.Recipients).All where !mail.IsSent orderby mail.Created ascending select mail; return(unsent.FirstOrDefault()); } }
private async Task <IEnumerable <GeneratedPairs> > Generate() { using (await access.Read()) { var ready = from world in worlds.NotDeleted where world.Account.Status != AccountStatus.Deleted from pairing in world.Pairings where !pairing.IsComplete && pairing.Date < DateTime.UtcNow select pairing; return(ready.ToList().Select(generator.For).ToList()); } }