Esempio n. 1
0
        public async Task Test_DatabaseService_Add_And_Remove_MswSurfspot()
        {
            // Arrange
            var mswSurfSpot = new MswSurfSpot()
            {
                Url = "Msw Test Url", Name = "Msw Test Name", FullStars = 2, BlurredStars = 1
            };
            var dbService = new DatabaseService();

            // Act
            await dbService.AddMswSurfSpotAsync(mswSurfSpot);

            var allMswSurfSpots = await dbService.GetAllMswSurfSpotsAsync();

            // Assert
            allMswSurfSpots.Any(s => s.Url == mswSurfSpot.Url).Should().BeTrue();

            // Act
            await dbService.RemoveMswSurfSpotAsync(mswSurfSpot);

            allMswSurfSpots = await dbService.GetAllMswSurfSpotsAsync();

            // Assert
            allMswSurfSpots.Any(s => s.Url == mswSurfSpot.Url).Should().BeFalse();
        }
Esempio n. 2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            MswSurfSpot = await _dataBaseService.GetMswSurfSpotAsync(id.Value);

            if (MswSurfSpot == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }

            MswSurfSpot = await _dataBaseService.GetMswSurfSpotAsync(id.Value);

            if (MswSurfSpot != null)
            {
                await _dataBaseService.RemoveMswSurfSpotAsync(MswSurfSpot);
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 4
0
        public ISet <DayOfWeek> EvaluateMswData(MswSwellData mswSwellData, MswSurfSpot mswSurfSpot)
        {
            ISet <DayOfWeek> swellDates = new HashSet <DayOfWeek>();

            foreach (var day in mswSwellData)
            {
                foreach (var hour in day.Value)
                {
                    if (HasDaylight(hour.Key) && hour.Value.FullStars >= mswSurfSpot.FullStars && hour.Value.BlurredStars >= mswSurfSpot.BlurredStars)
                    {
                        swellDates.Add(hour.Value.Timestamp.DayOfWeek);
                    }
                }
            }

            return(swellDates);
        }
Esempio n. 5
0
 public Task RemoveMswSurfSpotAsync(MswSurfSpot mswSurfSpot)
 {
     using var db = new SurfsUpDbContext();
     db.Remove(mswSurfSpot);
     return(db.SaveChangesAsync());
 }
Esempio n. 6
0
 public Task ChangeMswSurfSpotAsync(MswSurfSpot mswSurfSpot)
 {
     using var db = new SurfsUpDbContext();
     db.Attach(mswSurfSpot).State = EntityState.Modified;
     return(db.SaveChangesAsync());
 }