public async Task Test_DatabaseService_Add_And_Remove_BafuSurfspot() { // Arrange var bafuSurfSpot = new BafuSurfSpot() { Url = "Bafu Test Url", Name = "Bafu Test Name", Outflow = 250 }; var dbService = new DatabaseService(); // Act await dbService.AddBafuSurfSpotAsync(bafuSurfSpot); var allBafuSurfSpots = await dbService.GetAllBafuSurfSpotsAsync(); // Assert allBafuSurfSpots.Any(s => s.Url == bafuSurfSpot.Url).Should().BeTrue(); // Act await dbService.RemoveBafuSurfSpotAsync(bafuSurfSpot); allBafuSurfSpots = await dbService.GetAllBafuSurfSpotsAsync(); // Assert allBafuSurfSpots.Any(s => s.Url == bafuSurfSpot.Url).Should().BeFalse(); }
public async Task <IActionResult> OnGetAsync(int?id) { if (!id.HasValue) { return(NotFound()); } BafuSurfSpot = await _dataBaseService.GetBafuSurfSpotAsync(id.Value); if (BafuSurfSpot == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (!id.HasValue) { return(NotFound()); } BafuSurfSpot = await _dataBaseService.GetBafuSurfSpotAsync(id.Value); if (BafuSurfSpot != null) { await _dataBaseService.RemoveBafuSurfSpotAsync(BafuSurfSpot); } return(RedirectToPage("./Index")); }
public bool IsFiring(BafuData bafuData, BafuSurfSpot bafuSurfSpot) { return(bafuData.OutflowCurrent > bafuSurfSpot.Outflow || bafuData.OutflowMax24hours > bafuSurfSpot.Outflow); }
public Task RemoveBafuSurfSpotAsync(BafuSurfSpot bafuSurfSpot) { using var db = new SurfsUpDbContext(); db.Remove(bafuSurfSpot); return(db.SaveChangesAsync()); }
public Task ChangeBafuSurfSpotAsync(BafuSurfSpot bafuSurfSpot) { using var db = new SurfsUpDbContext(); db.Attach(bafuSurfSpot).State = EntityState.Modified; return(db.SaveChangesAsync()); }