Min lösning på övningen
This commit is contained in:
60
Vidly/Controllers/CustomersController.cs
Normal file
60
Vidly/Controllers/CustomersController.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Vidly.Models;
|
||||
using Vidly.ViewModels;
|
||||
|
||||
namespace Vidly.Controllers
|
||||
{
|
||||
public class CustomersController : Controller
|
||||
{
|
||||
List<Customer> customers = null;
|
||||
|
||||
public CustomersController()
|
||||
{
|
||||
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}
|
||||
};
|
||||
}
|
||||
|
||||
// GET: Vidly
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Customers()
|
||||
{
|
||||
|
||||
var viewModel = new CustomersViewModel()
|
||||
{
|
||||
Customers = customers
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Route("Customers/Details/{nr}")]
|
||||
public ActionResult Customer(int nr)
|
||||
{
|
||||
foreach(var cust in customers)
|
||||
{
|
||||
if (cust.Id == nr)
|
||||
{
|
||||
return View(cust);
|
||||
}
|
||||
}
|
||||
return View(new Customer { Name="",Id=0});
|
||||
}
|
||||
|
||||
public ActionResult Movies()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user