Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. public ActionResult Index(int id)
  2. {
  3. var users = db.Educacions.Where(e => e.EmpleadoId == id).FirstOrDefault();
  4. return View(db.Educacions.Where(e => e.EmpleadoId == id)
  5. .OrderBy(e => e.EducacionId)
  6. .ThenBy(e => e.EducacionId)
  7. .ToPagedList(1, 5));
  8. }
  9.  
  10. public async Task<ActionResult> Details(int? id)
  11. {
  12. if (id == null)
  13. {
  14. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  15. }
  16. Educacion educacion = await db.Educacions.FindAsync(id);
  17. if (educacion == null)
  18. {
  19. return HttpNotFound();
  20. }
  21. return View(educacion);
  22. }
  23.  
  24. // GET: Educacions/Create
  25. public ActionResult Create(int id)
  26. {
  27. var users = db.Educacions.Where(e => e.EmpleadoId == id).FirstOrDefault();
  28. var educacion = new Educacion { EmpleadoId = id, };
  29. return View(educacion);
  30.  
  31. //ViewBag.EmpleadoId = new SelectList(db.Empleadoes, "EmpleadoId", "EmpleadoId");
  32. //return View();
  33. }
  34.  
  35. [HttpPost]
  36. [ValidateAntiForgeryToken]
  37. public async Task<ActionResult> Create(Educacion educacion)
  38. {
  39. if (ModelState.IsValid)
  40. {
  41. db.Educacions.Add(educacion);
  42. await db.SaveChangesAsync();
  43. return RedirectToAction("Index");
  44. }
  45.  
  46. ViewBag.EmpleadoId = new SelectList(db.Empleadoes, "EmpleadoId", "EmpleadoId", educacion.EmpleadoId);
  47. return View(educacion);
  48. }
  49.  
  50. public async Task<ActionResult> Edit(int? id)
  51. {
  52. if (id == null)
  53. {
  54. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  55. }
  56. Educacion educacion = await db.Educacions.FindAsync(id);
  57. if (educacion == null)
  58. {
  59. return HttpNotFound();
  60. }
  61. ViewBag.EmpleadoId = new SelectList(db.Empleadoes, "EmpleadoId", "EmpleadoId", educacion.EmpleadoId);
  62. return View(educacion);
  63. }
  64.  
  65. [HttpPost]
  66. [ValidateAntiForgeryToken]
  67. public async Task<ActionResult> Edit(Educacion educacion)
  68. {
  69. if (ModelState.IsValid)
  70. {
  71. db.Entry(educacion).State = EntityState.Modified;
  72. await db.SaveChangesAsync();
  73. return RedirectToAction("Index");
  74. }
  75. ViewBag.EmpleadoId = new SelectList(db.Empleadoes, "EmpleadoId", "EmpleadoId", educacion.EmpleadoId);
  76. return View(educacion);
  77. }
  78.  
  79. // GET: Educacions/Delete/5
  80. public async Task<ActionResult> Delete(int? id)
  81. {
  82. if (id == null)
  83. {
  84. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  85. }
  86. Educacion educacion = await db.Educacions.FindAsync(id);
  87. if (educacion == null)
  88. {
  89. return HttpNotFound();
  90. }
  91. return View(educacion);
  92. }
  93.  
  94. [HttpPost, ActionName("Delete")]
  95. [ValidateAntiForgeryToken]
  96. public async Task<ActionResult> DeleteConfirmed(int id)
  97. {
  98. Educacion educacion = await db.Educacions.FindAsync(id);
  99. db.Educacions.Remove(educacion);
  100. await db.SaveChangesAsync();
  101. return RedirectToAction("Index");
  102. }
  103.  
  104. protected override void Dispose(bool disposing)
  105. {
  106. if (disposing)
  107. {
  108. db.Dispose();
  109. }
  110. base.Dispose(disposing);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement