Skip to content

Commit cfd4c7e

Browse files
authored
initial commit
1 parent c16465a commit cfd4c7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2001
-0
lines changed

App.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>

Data/WeatherForecast.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace STW.SurveyAppWithMVCBlazer.Data
2+
{
3+
public class WeatherForecast
4+
{
5+
public DateTime Date { get; set; }
6+
public int TemperatureC { get; set; }
7+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
8+
public string? Summary { get; set; }
9+
}
10+
}

Data/WeatherForecastService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace STW.SurveyAppWithMVCBlazer.Data
2+
{
3+
public class WeatherForecastService
4+
{
5+
private static readonly string[] Summaries = new[]
6+
{
7+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
8+
};
9+
10+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
11+
{
12+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
13+
{
14+
Date = startDate.AddDays(index),
15+
TemperatureC = Random.Shared.Next(-20, 55),
16+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
17+
}).ToArray());
18+
}
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using STW.SurveyAppWithMVCBlazer.Models;
3+
4+
namespace STW.SurveyAppWithMVCBlazer.DatabaseContext
5+
{
6+
public class ApplicationContext:DbContext
7+
{
8+
public ApplicationContext(DbContextOptions<ApplicationContext> options):base(options)
9+
{
10+
}
11+
public DbSet<Question> Questions { get; set; }
12+
public DbSet<Answer> Answers { get; set; }
13+
}
14+
}

Migrations/20220725071226_InitialMigration.Designer.cs

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace STW.SurveyAppWithMVCBlazer.Migrations
6+
{
7+
public partial class InitialMigration : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.CreateTable(
12+
name: "Questions",
13+
columns: table => new
14+
{
15+
Id = table.Column<int>(type: "int", nullable: false)
16+
.Annotation("SqlServer:Identity", "1, 1"),
17+
Text = table.Column<string>(type: "nvarchar(max)", nullable: true),
18+
Order = table.Column<int>(type: "int", nullable: false)
19+
},
20+
constraints: table =>
21+
{
22+
table.PrimaryKey("PK_Questions", x => x.Id);
23+
});
24+
25+
migrationBuilder.CreateTable(
26+
name: "Answers",
27+
columns: table => new
28+
{
29+
Id = table.Column<int>(type: "int", nullable: false)
30+
.Annotation("SqlServer:Identity", "1, 1"),
31+
Text = table.Column<string>(type: "nvarchar(max)", nullable: true),
32+
IsValidAnswer = table.Column<bool>(type: "bit", nullable: false),
33+
QuestionId = table.Column<int>(type: "int", nullable: false)
34+
},
35+
constraints: table =>
36+
{
37+
table.PrimaryKey("PK_Answers", x => x.Id);
38+
table.ForeignKey(
39+
name: "FK_Answers_Questions_QuestionId",
40+
column: x => x.QuestionId,
41+
principalTable: "Questions",
42+
principalColumn: "Id",
43+
onDelete: ReferentialAction.Cascade);
44+
});
45+
46+
migrationBuilder.CreateIndex(
47+
name: "IX_Answers_QuestionId",
48+
table: "Answers",
49+
column: "QuestionId",
50+
unique: true);
51+
}
52+
53+
protected override void Down(MigrationBuilder migrationBuilder)
54+
{
55+
migrationBuilder.DropTable(
56+
name: "Answers");
57+
58+
migrationBuilder.DropTable(
59+
name: "Questions");
60+
}
61+
}
62+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// <auto-generated />
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Metadata;
5+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6+
using STW.SurveyAppWithMVCBlazer.DatabaseContext;
7+
8+
#nullable disable
9+
10+
namespace STW.SurveyAppWithMVCBlazer.Migrations
11+
{
12+
[DbContext(typeof(ApplicationContext))]
13+
partial class ApplicationContextModelSnapshot : ModelSnapshot
14+
{
15+
protected override void BuildModel(ModelBuilder modelBuilder)
16+
{
17+
#pragma warning disable 612, 618
18+
modelBuilder
19+
.HasAnnotation("ProductVersion", "6.0.7")
20+
.HasAnnotation("Relational:MaxIdentifierLength", 128);
21+
22+
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
23+
24+
modelBuilder.Entity("STW.SurveyAppWithMVCBlazer.Models.Answer", b =>
25+
{
26+
b.Property<int>("Id")
27+
.ValueGeneratedOnAdd()
28+
.HasColumnType("int");
29+
30+
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
31+
32+
b.Property<bool>("IsValidAnswer")
33+
.HasColumnType("bit");
34+
35+
b.Property<int>("QuestionId")
36+
.HasColumnType("int");
37+
38+
b.Property<string>("Text")
39+
.HasColumnType("nvarchar(max)");
40+
41+
b.HasKey("Id");
42+
43+
b.HasIndex("QuestionId")
44+
.IsUnique();
45+
46+
b.ToTable("Answers");
47+
});
48+
49+
modelBuilder.Entity("STW.SurveyAppWithMVCBlazer.Models.Question", b =>
50+
{
51+
b.Property<int>("Id")
52+
.ValueGeneratedOnAdd()
53+
.HasColumnType("int");
54+
55+
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
56+
57+
b.Property<int>("Order")
58+
.HasColumnType("int");
59+
60+
b.Property<string>("Text")
61+
.HasColumnType("nvarchar(max)");
62+
63+
b.HasKey("Id");
64+
65+
b.ToTable("Questions");
66+
});
67+
68+
modelBuilder.Entity("STW.SurveyAppWithMVCBlazer.Models.Answer", b =>
69+
{
70+
b.HasOne("STW.SurveyAppWithMVCBlazer.Models.Question", "Question")
71+
.WithOne("Answer")
72+
.HasForeignKey("STW.SurveyAppWithMVCBlazer.Models.Answer", "QuestionId")
73+
.OnDelete(DeleteBehavior.Cascade)
74+
.IsRequired();
75+
76+
b.Navigation("Question");
77+
});
78+
79+
modelBuilder.Entity("STW.SurveyAppWithMVCBlazer.Models.Question", b =>
80+
{
81+
b.Navigation("Answer")
82+
.IsRequired();
83+
});
84+
#pragma warning restore 612, 618
85+
}
86+
}
87+
}

Models/Answer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace STW.SurveyAppWithMVCBlazer.Models
4+
{
5+
public class Answer: BaseModel
6+
{
7+
public Answer()
8+
{
9+
}
10+
public Answer(string text, bool isValidAnswer, int questionId, Question question)
11+
{
12+
Text = text;
13+
IsValidAnswer = isValidAnswer;
14+
QuestionId = questionId;
15+
Question = question;
16+
}
17+
18+
public string? Text { get; set; }
19+
public bool IsValidAnswer { get; set; } = false;
20+
[ForeignKey("QuestionId")]
21+
public int QuestionId { get; set; }
22+
public Question Question { get; set; } = new Question();
23+
}
24+
}

Models/BaseModel.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace STW.SurveyAppWithMVCBlazer.Models
4+
{
5+
public class BaseModel
6+
{
7+
public BaseModel()
8+
{
9+
}
10+
public BaseModel(int id)
11+
{
12+
Id = id;
13+
}
14+
15+
[Key]
16+
public int Id { get; set; }
17+
}
18+
}

Models/Question.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace STW.SurveyAppWithMVCBlazer.Models
2+
{
3+
public class Question: BaseModel
4+
{
5+
public Question()
6+
{
7+
}
8+
public Question(int id,string text, int order):base(id)
9+
{
10+
this.Text = text;
11+
this.Order = order;
12+
}
13+
public string? Text { get; set; }
14+
public int Order { get; set; }
15+
public ICollection<Answer> Answers { get; set; } = new List<Answer>();
16+
}
17+
}

0 commit comments

Comments
 (0)