Skip to content

Commit 8d3159d

Browse files
author
Dhyan
committed
Add project files.
1 parent 110f756 commit 8d3159d

File tree

210 files changed

+151761
-0
lines changed

Some content is hidden

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

210 files changed

+151761
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using BulkeyRazor_Temp.Model;
2+
using Microsoft.EntityFrameworkCore;
3+
4+
namespace BulkeyRazor_Temp.Data
5+
{
6+
public class ApplicationDbContext : DbContext
7+
{
8+
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
9+
{
10+
11+
}
12+
public DbSet<Category> Categories { get; set; }
13+
14+
protected override void OnModelCreating(ModelBuilder modelBuilder)
15+
{
16+
modelBuilder.Entity<Category>().HasData(
17+
new Category { Id = 1, Name = "Action", DisplayOrder = 1 },
18+
new Category { Id = 2, Name = "SciFi", DisplayOrder = 2 },
19+
new Category { Id = 3, Name = "History", DisplayOrder = 3 }
20+
);
21+
}
22+
}
23+
}

BulkeyRazor_Temp/Migrations/20230721120146_addCategoryToDb.Designer.cs

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
6+
7+
namespace BulkeyRazor_Temp.Migrations
8+
{
9+
/// <inheritdoc />
10+
public partial class addCategoryToDb : Migration
11+
{
12+
/// <inheritdoc />
13+
protected override void Up(MigrationBuilder migrationBuilder)
14+
{
15+
migrationBuilder.CreateTable(
16+
name: "Categories",
17+
columns: table => new
18+
{
19+
Id = table.Column<int>(type: "int", nullable: false)
20+
.Annotation("SqlServer:Identity", "1, 1"),
21+
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
22+
DisplayOrder = table.Column<int>(type: "int", nullable: false)
23+
},
24+
constraints: table =>
25+
{
26+
table.PrimaryKey("PK_Categories", x => x.Id);
27+
});
28+
29+
migrationBuilder.InsertData(
30+
table: "Categories",
31+
columns: new[] { "Id", "DisplayOrder", "Name" },
32+
values: new object[,]
33+
{
34+
{ 1, 1, "Action" },
35+
{ 2, 2, "SciFi" },
36+
{ 3, 3, "History" }
37+
});
38+
}
39+
40+
/// <inheritdoc />
41+
protected override void Down(MigrationBuilder migrationBuilder)
42+
{
43+
migrationBuilder.DropTable(
44+
name: "Categories");
45+
}
46+
}
47+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// <auto-generated />
2+
using BulkeyRazor_Temp.Data;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Infrastructure;
5+
using Microsoft.EntityFrameworkCore.Metadata;
6+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7+
8+
#nullable disable
9+
10+
namespace BulkeyRazor_Temp.Migrations
11+
{
12+
[DbContext(typeof(ApplicationDbContext))]
13+
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
14+
{
15+
protected override void BuildModel(ModelBuilder modelBuilder)
16+
{
17+
#pragma warning disable 612, 618
18+
modelBuilder
19+
.HasAnnotation("ProductVersion", "7.0.9")
20+
.HasAnnotation("Relational:MaxIdentifierLength", 128);
21+
22+
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
23+
24+
modelBuilder.Entity("BulkeyRazor_Temp.Model.Category", b =>
25+
{
26+
b.Property<int>("Id")
27+
.ValueGeneratedOnAdd()
28+
.HasColumnType("int");
29+
30+
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
31+
32+
b.Property<int>("DisplayOrder")
33+
.HasColumnType("int");
34+
35+
b.Property<string>("Name")
36+
.IsRequired()
37+
.HasColumnType("nvarchar(max)");
38+
39+
b.HasKey("Id");
40+
41+
b.ToTable("Categories");
42+
43+
b.HasData(
44+
new
45+
{
46+
Id = 1,
47+
DisplayOrder = 1,
48+
Name = "Action"
49+
},
50+
new
51+
{
52+
Id = 2,
53+
DisplayOrder = 2,
54+
Name = "SciFi"
55+
},
56+
new
57+
{
58+
Id = 3,
59+
DisplayOrder = 3,
60+
Name = "History"
61+
});
62+
});
63+
#pragma warning restore 612, 618
64+
}
65+
}
66+
}

BulkeyRazor_Temp/Model/Category.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel;
3+
4+
namespace BulkeyRazor_Temp.Model
5+
{
6+
public class Category
7+
{
8+
[Key]
9+
public int Id { get; set; }
10+
[Required]
11+
[DisplayName("Category Name")]
12+
public string Name { get; set; }
13+
14+
[Range(1, 100, ErrorMessage = "Must me between 1 to 100")]
15+
[DisplayName("Display Order")]
16+
public int DisplayOrder { get; set; }
17+
18+
}
19+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@page
2+
@model BulkeyRazor_Temp.Pages.Categories.CreateModel
3+
4+
5+
<form method="post" >
6+
<div class="border p-2">
7+
<h3>CREATE CATEGORY</h3>
8+
</div>
9+
<div class="border p-4">
10+
<div asp-validation-summary="ModelOnly"></div>
11+
<div class= "form-group mb-2">
12+
<label asp-for="category.Name"></label>
13+
<input asp-for="category.Name" class="form-control" />
14+
<span asp-validation-for="category.Name" class="text-danger"></span>
15+
</div>
16+
<div class="form-group mb-2">
17+
<label asp-for="category.DisplayOrder"></label>
18+
<input asp-for="category.DisplayOrder" class="form-control" />
19+
<span asp-validation-for="category.DisplayOrder" class="text-danger"></span>
20+
</div>
21+
<div class="d-flex justify-content-between align-items">
22+
<button type="submit" class="btn btn-dark m-2" style="width:50%">CRETAE</button>
23+
<a asp-page="/Categories/Index" class="btn btn-light btn-outline-dark m-2" style="width:50%">Back to List</a>
24+
</div>
25+
</div>
26+
</form>
27+
28+
@section Scripts{
29+
@{
30+
<partial name = "_ValidationScriptsPartial"/>
31+
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using BulkeyRazor_Temp.Data;
2+
using BulkeyRazor_Temp.Model;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.Mvc.RazorPages;
5+
6+
namespace BulkeyRazor_Temp.Pages.Categories
7+
{
8+
public class CreateModel : PageModel
9+
{
10+
11+
private readonly ApplicationDbContext _db;
12+
public CreateModel(ApplicationDbContext db)
13+
{
14+
_db = db;
15+
}
16+
17+
[BindProperty]
18+
public Category category { get; set; }
19+
20+
21+
public void OnGet()
22+
{
23+
}
24+
25+
public IActionResult OnPost()
26+
{
27+
_db.Categories.Add(category);
28+
_db.SaveChanges();
29+
TempData["success"] = "CATEGORY CREATED SUCCESSFULLY";
30+
return RedirectToPage("Index");
31+
}
32+
}
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@page
2+
@model BulkeyRazor_Temp.Pages.Categories.DeleteModel
3+
4+
5+
<form method="post">
6+
<div class="border p-2">
7+
<h3>DELETE CATEGORY</h3>
8+
</div>
9+
<div class="border p-4">
10+
<div asp-validation-summary="ModelOnly"></div>
11+
<input asp-for="category.Id" hidden />
12+
<div class="form-group mb-2">
13+
<label asp-for="category.Name"></label>
14+
<input asp-for="category.Name" class="form-control" disabled />
15+
</div>
16+
<div class="form-group mb-2">
17+
<label asp-for="category.DisplayOrder"></label>
18+
<input asp-for="category.DisplayOrder" class="form-control " disabled />
19+
</div>
20+
<div class="d-flex justify-content-between align-items">
21+
<button type="submit" class="btn btn-danger m-2" style="width:50%">DELETE</button>
22+
<a asp-page="/Categories/Index" class="btn btn-light btn-outline-dark m-2" style="width:50%">Back to List</a>
23+
</div>
24+
</div>
25+
</form>
26+
27+
@section Scripts{
28+
@{
29+
<partial name="_ValidationScriptsPartial" />
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using BulkeyRazor_Temp.Data;
2+
using BulkeyRazor_Temp.Model;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.Mvc.RazorPages;
5+
6+
namespace BulkeyRazor_Temp.Pages.Categories
7+
{
8+
public class DeleteModel : PageModel
9+
{
10+
11+
private readonly ApplicationDbContext _db;
12+
[BindProperty]
13+
public Category category { get; set; }
14+
15+
16+
public DeleteModel(ApplicationDbContext db)
17+
{
18+
_db = db;
19+
}
20+
public void OnGet(int? Id)
21+
{
22+
if (Id != null)
23+
{
24+
category = _db.Categories.Find(Id);
25+
}
26+
}
27+
28+
public IActionResult OnPost()
29+
{
30+
_db.Categories.Remove(category);
31+
_db.SaveChanges();
32+
TempData["success"] = "CATEGORY DELETED SUCCESSFULLY";
33+
return RedirectToPage("Index");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)