Guest User

Untitled

a guest
Jun 22nd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public class Match
  2. {
  3. public int Id { get; set; }
  4. public string Team1 { get; set; }
  5. public string Team2 { get; set; }
  6. public int Rate { get; set; }
  7. public int BO { get; set; }
  8. }
  9.  
  10. public class Person
  11. {
  12. public int Id { get; set; }
  13. public string Name { get; set; }
  14. public int Days { get; set; }
  15. public DateTime Date { get; set; }
  16. }
  17.  
  18. public class MatchContext : DbContext
  19. {
  20. public DbSet<Match> Matches { get; set; }
  21. public DbSet<Person> Persons { get; set; }
  22. }
  23.  
  24. public class NeuroController : Controller
  25. {
  26.  
  27. MatchContext db = new MatchContext();
  28. public ActionResult Index()
  29. {
  30. return View(db);
  31. }
  32. protected override void Dispose(bool disposing)
  33. {
  34. db.Dispose();
  35. base.Dispose(disposing);
  36. }
  37. }
  38.  
  39. @model IEnumerable<NB.Models.Match>
  40. @{
  41. ...
  42.  
  43. public class ViewModel
  44. {
  45. public IEnumerable<Match> Matches {get;set;}
  46. public IEnumerable<Person> Persons {get;set;}
  47.  
  48. //или же можно указать конкретные свойства из классов
  49. }
  50.  
  51. public class NeuroController : Controller
  52. {
  53. public ActionResult GetViewModel()
  54. {
  55. var db = new MatchContext();
  56. var matches = db.Matches.ToList();
  57. var persons = db.Persons.ToList();
  58. var model = new ViewModel { Matches = matches, Persons = persons};
  59. return View(model);
  60. }
  61. }
Add Comment
Please, Sign In to add comment