File tree 3 files changed +42
-0
lines changed
src/Examples/JsonApiDotNetCoreExample
3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ namespace JsonApiDotNetCoreExample.Data;
10
10
public sealed class AppDbContext : DbContext
11
11
{
12
12
public DbSet < TodoItem > TodoItems => Set < TodoItem > ( ) ;
13
+ public DbSet < PostIt > PostIts => Set < PostIt > ( ) ;
13
14
14
15
public AppDbContext ( DbContextOptions < AppDbContext > options )
15
16
: base ( options )
Original file line number Diff line number Diff line change
1
+ using System . ComponentModel . DataAnnotations ;
2
+ using JsonApiDotNetCore . Resources ;
3
+ using JsonApiDotNetCore . Resources . Annotations ;
4
+
5
+ namespace JsonApiDotNetCoreExample . Models ;
6
+
7
+ [ Resource ]
8
+ public class PostIt : Identifiable < int >
9
+ {
10
+ [ Attr ]
11
+ [ Required ]
12
+ public bool Actif { get ; set ; }
13
+
14
+ [ Attr ]
15
+ [ Required ]
16
+ public DateTime Date { get ; set ; }
17
+
18
+ [ Attr ]
19
+ [ MaxLength ( 2 , ErrorMessage = "Error" ) ]
20
+ public string Message { get ; set ; }
21
+
22
+ [ Attr ]
23
+ [ Required ]
24
+ public string RefOperateur { get ; set ; }
25
+ }
Original file line number Diff line number Diff line change 3
3
using JsonApiDotNetCore . Configuration ;
4
4
using JsonApiDotNetCore . Diagnostics ;
5
5
using JsonApiDotNetCoreExample . Data ;
6
+ using JsonApiDotNetCoreExample . Models ;
6
7
using Microsoft . AspNetCore . Authentication ;
7
8
using Microsoft . EntityFrameworkCore ;
8
9
using Microsoft . Extensions . DependencyInjection . Extensions ;
@@ -98,5 +99,20 @@ static async Task CreateDatabaseAsync(IServiceProvider serviceProvider)
98
99
await using AsyncServiceScope scope = serviceProvider . CreateAsyncScope ( ) ;
99
100
100
101
var dbContext = scope . ServiceProvider . GetRequiredService < AppDbContext > ( ) ;
102
+
103
+ await dbContext . Database . EnsureDeletedAsync ( ) ;
101
104
await dbContext . Database . EnsureCreatedAsync ( ) ;
105
+
106
+ var postIt = new PostIt
107
+ {
108
+ Id = 835405 ,
109
+ Actif = true ,
110
+ Date = DateTime . UtcNow ,
111
+ Message = "ab" ,
112
+ RefOperateur = "some-ref"
113
+ } ;
114
+
115
+ dbContext . PostIts . Add ( postIt ) ;
116
+
117
+ await dbContext . SaveChangesAsync ( ) ;
102
118
}
You can’t perform that action at this time.
0 commit comments