public async Task PutExistingClub(string clubName, Club updatedClub) { var policy = Policy.Handle <SqlException>().WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(15), }, (ext, timeSpan, retryCount, context) => { _logger.LogError(ext, $"Error - try retry (count: {retryCount}, timeSpan: {timeSpan})"); }); var existingClub = await policy.ExecuteAsync(() => _context.Clubs.FirstOrDefaultAsync(c => c.ClubName == clubName)); if (existingClub == null) { _logger.LogInformation($"Club with name {clubName} doesn't exists."); // TODO return error object with proper error code. throw new Exception("Entity not founded."); } existingClub.ClubName = updatedClub.ClubName; existingClub.City = updatedClub.City; existingClub.Founded = updatedClub.Founded; _context.Update(existingClub); await _context.SaveChangesAsync(); }
public Task SaveChangesAsync() { return(Context.SaveChangesAsync()); }