Files
Vidly2/Vidly/Controllers/CustomersController.cs
2019-01-19 17:08:56 +01:00

65 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Web.Mvc;
using Vidly.Models;
using Vidly.ViewModels;
namespace Vidly.Controllers
{
public class CustomersController : Controller
{
List<Customer> customers = null;
private ApplicationDbContext _context;
public CustomersController()
{
_context = new ApplicationDbContext();
customers = new List<Customer>
{
new Customer {Name="Nils Persson", Id=1},
new Customer {Name="Pelle Rundström",Id=2},
new Customer {Name="Ulla Ulriksson",Id=3}
};
}
protected override void Dispose(bool disposing)
{
_context.Dispose();
}
// GET: Vidly
public ActionResult Index()
{
return View();
}
public ActionResult Customers()
{
var viewModel = new CustomersViewModel()
{
Customers = _context.Customers.Include(c=>c.MembershipType).ToList()
};
return View(viewModel);
}
[Route("Customers/Details/{nr}")]
public ActionResult Customer(int nr)
{
var customer = _context.Customers.SingleOrDefault(c => c.Id == nr);
if (customer== null)
return HttpNotFound();
return View(customer);
}
public ActionResult Movies()
{
return View();
}
}
}