public async Task <IActionResult> AddRate(int id, TariffRate tariffRate) { var tariff = await _ercContext.Tariffs.FindAsync(id); tariff.AddRate(tariffRate); await _ercContext.SaveChangesAsync(); return(Ok(tariffRate)); }
public async Task <IActionResult> UpdateRate(int id, int rateId, TariffRate tariffRate) { if (rateId != tariffRate.Id || id == 0 || rateId == 0) { return(BadRequest()); } var tariff = await _ercContext.Tariffs.FirstOrDefaultAsync(t => t.Id == id); if (tariff is null) { return(NotFound()); } tariff.UpdateRate(tariffRate); await _ercContext.SaveChangesAsync(); return(Ok()); }
public void GetRate_GivenStartTimes_AndCurrentTime_ReturnsRate(string dayStartString, string nightStartString, string nowString, TariffRate expectedRate) { // Arrange var dayStart = TimeSpan.Parse(dayStartString); var nightStart = TimeSpan.Parse(nightStartString); var now = TimeSpan.Parse(nowString); // Act var rate = DateTimeHelper.GetRate(dayStart, nightStart, now); // Assert Assert.Equal(expectedRate, rate); }