Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using MovieApp.Models;
  7. using System.Data.Entity;
  8. using MovieApp.ViewModels;
  9.  
  10. namespace MovieApp.Controllers
  11. {
  12. public class CustomersController : Controller
  13. {
  14. private ApplicationDbContext _context;
  15.  
  16.  
  17. public CustomersController()
  18. {
  19. _context = new ApplicationDbContext();
  20. }
  21.  
  22. protected override void Dispose(bool disposing)
  23. {
  24. _context.Dispose();
  25. }
  26.  
  27.  
  28. public ActionResult New()
  29. {
  30.  
  31. var DBmebershipTypes= _context.MembershipTypes.ToList();
  32. var ViewModel = new NewCustomerViewModel()
  33. {
  34. MembershipTypes = DBmebershipTypes
  35.  
  36. };
  37. return View(ViewModel);
  38. }
  39.  
  40. [HttpPost]
  41. public ActionResult Create(Customer customer)
  42. {
  43. _context.Customers.Add(customer);
  44. // if (customer.MembershipTypeId == null)
  45. // return HttpNotFound();
  46. _context.SaveChanges();
  47. return RedirectToAction("Index", "Customers");
  48. }
  49.  
  50. // GET: Customers
  51. public ActionResult Index()
  52. {
  53. var customers = _context.Customers.Include(c => c.MembershipType).ToList();
  54. return View(customers);
  55. }
  56.  
  57. public ActionResult Details(int id)
  58. {
  59. var customer = _context.Customers.Include(c => c.MembershipTypeId).Single(c => c.Id == id);
  60. return View(customer);
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement