Lite upprensning bland kontroller och views, cutomers kan läggas till och uppdateras
This commit is contained in:
@ -23,13 +23,46 @@ namespace Vidly.Controllers
|
||||
_context.Dispose();
|
||||
}
|
||||
|
||||
// GET: Vidly
|
||||
public ActionResult Index()
|
||||
//// GET: Vidly
|
||||
//public ActionResult Index()
|
||||
//{
|
||||
// return View();
|
||||
//}
|
||||
|
||||
public ActionResult New()
|
||||
{
|
||||
return View();
|
||||
var membershipTypes = _context.MembershipTypes.ToList();
|
||||
var viewModel = new CustomerFormViewModel
|
||||
{
|
||||
Customer = new Customer(),
|
||||
MembershipTypes = membershipTypes
|
||||
};
|
||||
return View("CustomerForm",viewModel);
|
||||
}
|
||||
|
||||
public ActionResult Customers()
|
||||
[HttpPost]
|
||||
public ActionResult Save(Customer customer)
|
||||
{
|
||||
if(customer.Id==0)
|
||||
_context.Customers.Add(customer);
|
||||
else
|
||||
{
|
||||
var customerInDb = _context.Customers.Single(c => c.Id == customer.Id);
|
||||
// Mapper.Map(customer, customerInDb);
|
||||
|
||||
customerInDb.Name = customer.Name;
|
||||
customerInDb.BirthDate = customer.BirthDate;
|
||||
customerInDb.MembershipTypeId = customer.MembershipTypeId;
|
||||
customerInDb.IsSubscribedToNewsLetter = customer.IsSubscribedToNewsLetter;
|
||||
}
|
||||
_context.SaveChanges();
|
||||
|
||||
return RedirectToAction("Index","Customers");
|
||||
}
|
||||
|
||||
[Route("Customers")]
|
||||
[Route("Customers/Index")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
|
||||
var viewModel = new CustomersViewModel()
|
||||
@ -40,7 +73,6 @@ namespace Vidly.Controllers
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Route("Customers/Details/{nr}")]
|
||||
public ActionResult Customer(int nr)
|
||||
{
|
||||
var customer = _context.Customers.Include(c => c.MembershipType).SingleOrDefault(c => c.Id == nr);
|
||||
@ -49,9 +81,26 @@ namespace Vidly.Controllers
|
||||
return View(customer);
|
||||
}
|
||||
|
||||
public ActionResult Movies()
|
||||
public ActionResult Edit(int id)
|
||||
{
|
||||
return View();
|
||||
var customer = _context.Customers.SingleOrDefault(c=>c.Id==id);
|
||||
|
||||
if (customer == null)
|
||||
return HttpNotFound();
|
||||
|
||||
var viewModel = new CustomerFormViewModel
|
||||
{
|
||||
Customer = customer,
|
||||
MembershipTypes = _context.MembershipTypes.ToList()
|
||||
};
|
||||
|
||||
return View("CustomerForm", viewModel);
|
||||
|
||||
}
|
||||
|
||||
//public ActionResult Movies()
|
||||
//{
|
||||
// return View();
|
||||
//}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,10 @@ namespace Vidly.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
|
||||
[Route("")]
|
||||
[Route("Home")]
|
||||
[Route("Home/Index")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
|
||||
@ -18,7 +18,14 @@ namespace Vidly.Controllers
|
||||
_context = new ApplicationDbContext();
|
||||
}
|
||||
|
||||
public ActionResult Movies()
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
|
||||
[Route("Movies")]
|
||||
[Route("Movies/Index")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
var viewModel = new MoviesViewModel()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user