Skip to content
This repository was archived by the owner on May 11, 2023. It is now read-only.

Event category #25

Open
wants to merge 12 commits into
base: event-category
Choose a base branch
from
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
17 changes: 9 additions & 8 deletions CodingEventsDemo/CodingEventsDemo.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

Expand All @@ -12,17 +12,18 @@
<Folder Include="Data\" />
<Folder Include="ViewModels\" />
<Folder Include="Views\EventCategory\" />
<Folder Include="Views\Tag\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<None Remove="Microsoft.EntityFrameworkCore" />
<None Remove="Pomelo.EntityFrameworkCore.MySql" />
<None Remove="Microsoft.EntityFrameworkCore.Design" />
<None Remove="Views\Tag\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
25 changes: 25 additions & 0 deletions CodingEventsDemo/CodingEventsDemo.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1703.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodingEventsDemo", "CodingEventsDemo.csproj", "{33BFA655-C28C-4D2C-AD92-7D9E1D909008}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{33BFA655-C28C-4D2C-AD92-7D9E1D909008}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33BFA655-C28C-4D2C-AD92-7D9E1D909008}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33BFA655-C28C-4D2C-AD92-7D9E1D909008}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33BFA655-C28C-4D2C-AD92-7D9E1D909008}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4099042F-0400-4C61-BBA5-6463A59889B8}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion CodingEventsDemo/Controllers/EventCategoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System.Threading.Tasks;
using CodingEventsDemo.Data;
using CodingEventsDemo.Models;
using Microsoft.AspNetCore.Mvc;
using CodingEventsDemo.ViewModels;
using Microsoft.AspNetCore.Mvc;

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

Expand Down
23 changes: 19 additions & 4 deletions CodingEventsDemo/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
using CodingEventsDemo.Models;
using CodingEventsDemo.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

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

namespace coding_events_practice.Controllers
{
public class EventsController : Controller
{

private EventDbContext context;

public EventsController(EventDbContext dbContext)
Expand All @@ -24,14 +24,17 @@ public EventsController(EventDbContext dbContext)
// GET: /<controller>/
public IActionResult Index()
{
List<Event> events = context.Events.ToList();
List<Event> events = context.Events
.Include(e => e.Category)
.ToList();

return View(events);
}

public IActionResult Add()
{
AddEventViewModel addEventViewModel = new AddEventViewModel();
List<EventCategory> categories = context.Categories.ToList();
AddEventViewModel addEventViewModel = new AddEventViewModel(categories);

return View(addEventViewModel);
}
Expand All @@ -41,12 +44,13 @@ public IActionResult Add(AddEventViewModel addEventViewModel)
{
if (ModelState.IsValid)
{
EventCategory category = context.Categories.Find(addEventViewModel.CategoryId);
Event newEvent = new Event
{
Name = addEventViewModel.Name,
Description = addEventViewModel.Description,
ContactEmail = addEventViewModel.ContactEmail,
Type = addEventViewModel.Type
Category = category
};

context.Events.Add(newEvent);
Expand Down Expand Up @@ -78,5 +82,16 @@ public IActionResult Delete(int[] eventIds)

return Redirect("/Events");
}

// /Events/Detail/X
public IActionResult Detail(int id)
{
Event theEvent = context.Events
.Include(e => e.Category)
.Single(e => e.Id == id);

EventDetailViewModel viewModel = new EventDetailViewModel(theEvent);
return View(viewModel);
}
}
}
80 changes: 80 additions & 0 deletions CodingEventsDemo/Controllers/TagController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CodingEventsDemo.Data;
using CodingEventsDemo.Models;
using CodingEventsDemo.ViewModels;
using Microsoft.AspNetCore.Mvc;

namespace CodingEventsDemo.Controllers
{
public class TagController : Controller
{
private EventDbContext context;

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

// GET: /<controller>/
public IActionResult Index()
{
List<Tag> tags = context.Tags.ToList();
return View(tags);
}

public IActionResult Add()
{
Tag tag = new Tag();
return View(tag);
}

[HttpPost]
public IActionResult Add(Tag tag)
{
if (ModelState.IsValid)
{
context.Tags.Add(tag);
context.SaveChanges();
return Redirect("/Tag/");
}

return View("Add", tag);
}

public IActionResult AddEvent(int id)
{
Event theEvent = context.Events.Find(id);
List<Tag> possibleTags = context.Tags.ToList();

AddEventTagViewModel viewModel = new AddEventTagViewModel(theEvent, possibleTags);

return View(viewModel);
}

[HttpPost]
public IActionResult AddEvent(AddEventTagViewModel viewModel)
{
if (ModelState.IsValid)
{
int eventId = viewModel.EventId;
int tagId = viewModel.TagId;

EventTag eventTag = new EventTag
{
EventId = eventId,
TagId = tagId
};

context.EventTags.Add(eventTag);
context.SaveChanges();

return Redirect("/Events/Detail/" + eventId);
}

return View(viewModel);
}
}
}

7 changes: 7 additions & 0 deletions CodingEventsDemo/Data/EventDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ public class EventDbContext : DbContext
{
public DbSet<Event> Events { get; set; }
public DbSet<EventCategory> Categories { get; set; }
public DbSet<Tag> Tags { get; set; }
public DbSet<EventTag> EventTags { get; set; }

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

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EventTag>().HasKey(et => new { et.EventId, et.TagId });
}
}
}

This file was deleted.

33 changes: 0 additions & 33 deletions CodingEventsDemo/Migrations/20200622195148_InitialMigration.cs

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions CodingEventsDemo/Migrations/20200625184338_MyInitialMigration.cs

This file was deleted.

Loading