public LimitDefinition PatchDefinition(string path, string duration, PatchRequestDefinition data) { if (path == "" || path == null) { throw new NullPathException(); } if (duration == "" || duration == null) { throw new NullDurationException(); } if (_dataService.GetDefinitions(path, false).Where(x => x.Duration.Span == duration).FirstOrDefault() == null) { throw new PathNotDefinedException(); } if (data.NewAmountUtilizedLimit < 0 && data.NewAmountUtilizedLimit != -1) { throw new InvalidAmountException(); } if (data.NewTimerUtilizedLimit < 0 && data.NewTimerUtilizedLimit != -1) { throw new InvalidTimerLimitException(); } _dataService.PatchLimit(path, duration, data); LimitDefinition result = _dataService.GetDefinitions(path, false).Where(x => x.Duration.Span == duration).FirstOrDefault(); return(result); }
public void PatchLimit(string path, string duration, PatchRequestDefinition data) { using (var connection = new SqlConnection(_configuration.GetConnectionString("DefaultConnection"))) { using (SqlCommand command = new SqlCommand("patch-limit")) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@path", path); command.Parameters.AddWithValue("@duration", duration); command.Parameters.AddWithValue("@amountutilizedlimit", data.NewAmountUtilizedLimit); command.Parameters.AddWithValue("@timerutilizedlimit", data.NewTimerUtilizedLimit); command.Connection = connection; connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } }