Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CodingEvents/CodingEvents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,30 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<None Remove="Views\Events\" />
<None Remove="Data\" />
<None Remove="ViewModels\" />
<None Remove="Pomelo.EntityFrameworkCore.MySql" />
<None Remove="Microsoft.EntityFrameworkCore.Relational" />
<None Remove="Microsoft.EntityFrameworkCore.Design" />
<None Remove="Views\EventCategory\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\Events\" />
<Folder Include="Data\" />
<Folder Include="ViewModels\" />
<Folder Include="Views\EventCategory\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
60 changes: 60 additions & 0 deletions CodingEvents/Controllers/EventCategoryController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CodingEvents.Data;
using CodingEvents.Models;
using CodingEvents.ViewModels;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace CodingEvents.Controllers
{
public class EventCategoryController : Controller
{
private EventDbContext context;

public EventCategoryController(EventDbContext dbContext)
{
context = dbContext;
}

// GET: /<controller>/
[HttpGet]
public IActionResult Index()
{
List<EventCategory> categories = context.Categories.ToList();

return View(categories);
}

[HttpGet]
[Route("EventCategory/Create")]
public IActionResult Create()
{
AddEventCategoryViewModel addEventCategoryViewModel = new AddEventCategoryViewModel();

return View(addEventCategoryViewModel);
}

[HttpPost]
public IActionResult ProcessCreateEventCategoryForm(AddEventCategoryViewModel addEventCategoryViewModel)
{
if (ModelState.IsValid)
{
EventCategory theCategory = new EventCategory
{
Name = addEventCategoryViewModel.Name
};

context.Categories.Add(theCategory);
context.SaveChanges();

return Redirect("/EventCategory");
}
return View("Create", addEventCategoryViewModel);
}
}
}

82 changes: 82 additions & 0 deletions CodingEvents/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CodingEvents.Data;
using CodingEvents.Models;
using Microsoft.AspNetCore.Mvc;
using CodingEvents.ViewModels;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace CodingEvents.Controllers
{
public class EventsController : Controller
{
private EventDbContext context;

public EventsController(EventDbContext dbContext)
{
context = dbContext;
}
// GET: /<controller>/
public IActionResult Index()
{
List<Event> events = context.Events.ToList();

return View(events);
}

[HttpGet]
public IActionResult Add()
{
AddEventViewModel addEventViewModel = new AddEventViewModel();

return View(addEventViewModel);
}

[HttpPost]
public IActionResult Add(AddEventViewModel addEventViewModel)
{
if (ModelState.IsValid)
{
Event newEvent = new Event
{
Name = addEventViewModel.Name,
Description = addEventViewModel.Description,
ContactEmail = addEventViewModel.ContactEmail,
Type = addEventViewModel.Type
};

context.Events.Add(newEvent);
context.SaveChanges();

return Redirect("/Events");
}

return View(addEventViewModel);
}

public IActionResult Delete()
{
ViewBag.events = context.Events.ToList();

return View();
}

[HttpPost]
public IActionResult Delete(int[] eventIds)
{
foreach (int eventId in eventIds)
{
Event? theEvent = context.Events.Find(eventId);
context.Events.Remove(theEvent);
}

context.SaveChanges();

return Redirect("/Events");
}
}
}

18 changes: 18 additions & 0 deletions CodingEvents/Data/EventDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using CodingEvents.Models;
using Microsoft.EntityFrameworkCore;

namespace CodingEvents.Data
{
public class EventDbContext : DbContext
{
public DbSet<Event> Events { get; set; }
public DbSet<EventCategory> Categories { get; set; }


public EventDbContext(DbContextOptions<EventDbContext> options) : base(options)
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions CodingEvents/Migrations/20230308200850_InitialMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CodingEvents.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "Events",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Description = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ContactEmail = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_Events", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Events");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions CodingEvents/Migrations/20230308201656_ContextAddedMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CodingEvents.Migrations
{
/// <inheritdoc />
public partial class ContextAddedMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{

}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{

}
}
}
Loading