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
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>ClearBlueDesign.EntityFrameworkCore.Scaffolder.Samples.Web</AssemblyName>
<RootNamespace>ClearBlueDesign.EntityFrameworkCore.Scaffolder.Samples.Web</RootNamespace>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.1.4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.3.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EntityFrameworkCore.Scaffolder\ClearBlueDesign.EntityFrameworkCore.Scaffolder.csproj" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
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 ClearBlueDesign.EntityFrameworkCore.Scaffolder.Samples.Web.Data;

namespace ClearBlueDesign.EntityFrameworkCore.Scaffolder.Samples.Web.Controllers
{
public class CategoryController : Controller
{
private readonly DataContext _context;

public CategoryController(DataContext context)
{
_context = context;
}

// GET: Category
public async Task<IActionResult> Index()
{
return View(await _context.Categories.ToListAsync());
}

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

var category = await _context.Categories
.FirstOrDefaultAsync(m => m.CategoryId == id);
if (category == null)
{
return NotFound();
}

return View(category);
}

// GET: Category/Create
public IActionResult Create()
{
return View();
}

// POST: Category/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("CategoryId,CategoryName,Description,Picture")] Category category)
{
if (ModelState.IsValid)
{
_context.Add(category);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(category);
}

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

var category = await _context.Categories.FindAsync(id);
if (category == null)
{
return NotFound();
}
return View(category);
}

// POST: Category/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("CategoryId,CategoryName,Description,Picture")] Category category)
{
if (id != category.CategoryId)
{
return NotFound();
}

if (ModelState.IsValid)
{
try
{
_context.Update(category);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!CategoryExists(category.CategoryId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(category);
}

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

var category = await _context.Categories
.FirstOrDefaultAsync(m => m.CategoryId == id);
if (category == null)
{
return NotFound();
}

return View(category);
}

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

private bool CategoryExists(int id)
{
return _context.Categories.Any(e => e.CategoryId == id);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
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 ClearBlueDesign.EntityFrameworkCore.Scaffolder.Samples.Web.Data;

namespace ClearBlueDesign.EntityFrameworkCore.Scaffolder.Samples.Web.Controllers
{
public class CustomerController : Controller
{
private readonly DataContext _context;

public CustomerController(DataContext context)
{
_context = context;
}

// GET: Customer
public async Task<IActionResult> Index()
{
return View(await _context.Customers.ToListAsync());
}

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

var customer = await _context.Customers
.FirstOrDefaultAsync(m => m.CustomerId == id);
if (customer == null)
{
return NotFound();
}

return View(customer);
}

// GET: Customer/Create
public IActionResult Create()
{
return View();
}

// POST: Customer/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("CustomerId,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customer)
{
if (ModelState.IsValid)
{
_context.Add(customer);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(customer);
}

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

var customer = await _context.Customers.FindAsync(id);
if (customer == null)
{
return NotFound();
}
return View(customer);
}

// POST: Customer/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(string id, [Bind("CustomerId,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customer)
{
if (id != customer.CustomerId)
{
return NotFound();
}

if (ModelState.IsValid)
{
try
{
_context.Update(customer);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!CustomerExists(customer.CustomerId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(customer);
}

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

var customer = await _context.Customers
.FirstOrDefaultAsync(m => m.CustomerId == id);
if (customer == null)
{
return NotFound();
}

return View(customer);
}

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

private bool CustomerExists(string id)
{
return _context.Customers.Any(e => e.CustomerId == id);
}
}
}
Loading