This repository has been archived by the owner on May 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
124 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/FluxorIntegration/Store/Movies/InsertSeedDataReducer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Blazor.Fluxor; | ||
using FluxorIntegration.Models; | ||
|
||
namespace FluxorIntegration.Store.Movies | ||
{ | ||
public class InsertSeedDataReducer : IReducer<MovieState, InsertSeedMoviesAction> | ||
{ | ||
private Context Context { get; set; } | ||
|
||
public InsertSeedDataReducer(Context context) | ||
{ | ||
Context = context; | ||
} | ||
public MovieState Reduce(MovieState state, InsertSeedMoviesAction action) | ||
{ | ||
var query = from m in Context.Movies | ||
where m.Name == "Solo: A Star Wars Story" | ||
select m; | ||
if (!query.Any()) | ||
{ | ||
var movie = new Movie | ||
{ | ||
Name = "Solo: A Star Wars Story", | ||
Reviews = new List<Review> | ||
{ | ||
new Review {Stars = 4, Comment = "Pretty good!"}, | ||
new Review {Stars = 3, Comment = "Not as good as Rogue One"} | ||
} | ||
}; | ||
Context.Movies.Add(movie); | ||
} | ||
|
||
query = from m in Context.Movies | ||
where m.Name == "Isle of Dog" | ||
select m; | ||
if (!query.Any()) | ||
{ | ||
var movie = new Movie | ||
{ | ||
Name = "Isle of Dog", | ||
Reviews = new List<Review> | ||
{ | ||
new Review {Stars = 5, Comment = "Awesome stop motion movie!"} | ||
} | ||
}; | ||
Context.Movies.Add(movie); | ||
} | ||
|
||
Context.SaveChanges(); | ||
|
||
return new MovieState(Context.Movies); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Blazor.Fluxor; | ||
|
||
namespace FluxorIntegration.Store.Movies | ||
{ | ||
public class InsertSeedMoviesAction : IAction | ||
{ | ||
} | ||
} |