Skip to content

Commit

Permalink
Contoso 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitosh committed Sep 4, 2019
1 parent 2486eb1 commit 8a5f8c8
Show file tree
Hide file tree
Showing 92 changed files with 27,096 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.9" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions EFCoreAsp.NetMvcWebApp/ContosoUniversity006/ContosoUniversity.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 = 16.0.29201.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContosoUniversity", "ContosoUniversity.csproj", "{160E6C83-18BE-43A2-8B4A-C589953A326E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{160E6C83-18BE-43A2-8B4A-C589953A326E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{160E6C83-18BE-43A2-8B4A-C589953A326E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{160E6C83-18BE-43A2-8B4A-C589953A326E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{160E6C83-18BE-43A2-8B4A-C589953A326E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4DCD9066-7544-40F5-9862-AD6DFD30C7C6}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using ContosoUniversity.Data;
using ContosoUniversity.Models;

namespace ContosoUniversity.Controllers
{
public class CoursesController : Controller
{
private readonly SchoolContext _context;

public CoursesController(SchoolContext context)
{
_context = context;
}

// GET: Courses
public async Task<IActionResult> Index()
{
var courses = _context.Courses
.Include(c => c.Department)
.AsNoTracking();
return View(await courses.ToListAsync());
}

// GET: Courses/Details/5
public async Task<IActionResult> Details(int? id)
{
if (id == null)
{
return NotFound();
}

var course = await _context.Courses
.Include(c => c.Department)
.FirstOrDefaultAsync(m => m.CourseId == id);
if (course == null)
{
return NotFound();
}

return View(course);
}

// GET: Courses/Create
public IActionResult Create()
{
ViewData["DepartmentId"] = new SelectList(_context.Departments, "DepartmentId", "DepartmentId");
return View();
}

// POST: Courses/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("CourseId,Title,Credits,DepartmentId")] Course course)
{
if (ModelState.IsValid)
{
_context.Add(course);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["DepartmentId"] = new SelectList(_context.Departments, "DepartmentId", "DepartmentId", course.DepartmentId);
return View(course);
}

// GET: Courses/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}

var course = await _context.Courses.FindAsync(id);
if (course == null)
{
return NotFound();
}
ViewData["DepartmentId"] = new SelectList(_context.Departments, "DepartmentId", "DepartmentId", course.DepartmentId);
return View(course);
}

// POST: Courses/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, [Bind("CourseId,Title,Credits,DepartmentId")] Course course)
{
if (id != course.CourseId)
{
return NotFound();
}

if (ModelState.IsValid)
{
try
{
_context.Update(course);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!CourseExists(course.CourseId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["DepartmentId"] = new SelectList(_context.Departments, "DepartmentId", "DepartmentId", course.DepartmentId);
return View(course);
}

// GET: Courses/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if (id == null)
{
return NotFound();
}

var course = await _context.Courses
.Include(c => c.Department)
.FirstOrDefaultAsync(m => m.CourseId == id);
if (course == null)
{
return NotFound();
}

return View(course);
}

// POST: Courses/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
var course = await _context.Courses.FindAsync(id);
_context.Courses.Remove(course);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}

private bool CourseExists(int id)
{
return _context.Courses.Any(e => e.CourseId == id);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using ContosoUniversity.Models;
using ContosoUniversity.Data;
using System.Threading.Tasks;
using ContosoUniversity.SchoolViewModels;
using System.Linq;
using Microsoft.EntityFrameworkCore;

namespace ContosoUniversity.Controllers
{
public class HomeController : Controller
{
private readonly SchoolContext _context;

public HomeController(SchoolContext context)
{
_context = context;
}

public async Task<ActionResult> About()
{
IQueryable<EnrollmentDateGroup> data =
from student in _context.Students
group student by student.EnrollmentDate into dateGroup
select new EnrollmentDateGroup()
{
EnrollmentDate = dateGroup.Key,
StudentCount = dateGroup.Count()
};

return View(await data.AsNoTracking().ToListAsync());
}

public IActionResult Index()
{
return View();
}

public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";

return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
Loading

0 comments on commit 8a5f8c8

Please sign in to comment.