Advertisement
Guest User

CompradorController

a guest
Dec 18th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.Entity;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. using ProyectoV1.Models;
  10. using PagedList;
  11.  
  12. namespace ProyectoV1.Controllers
  13. {
  14. public class CompradorController : Controller
  15. {
  16. private bdagricolaEntities db = new bdagricolaEntities();
  17.  
  18. // GET: Comprador
  19. public ActionResult Index(int? page)
  20. {
  21. return View(db.comprador.ToList().ToPagedList(page ?? 1, 5));
  22. }
  23.  
  24. // GET: Comprador/Details/5
  25. public ActionResult Details(int? id)
  26. {
  27. if (id == null)
  28. {
  29. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  30. }
  31. comprador comprador = db.comprador.Find(id);
  32. if (comprador == null)
  33. {
  34. return HttpNotFound();
  35. }
  36. return View(comprador);
  37. }
  38.  
  39. // GET: Comprador/Create
  40. public ActionResult Create()
  41. {
  42. return View();
  43. }
  44.  
  45. // POST: Comprador/Create
  46. // Para protegerse de ataques de publicación excesiva, habilite las propiedades específicas a las que desea enlazarse. Para obtener
  47. // más información vea http://go.microsoft.com/fwlink/?LinkId=317598.
  48. [HttpPost]
  49. [ValidateAntiForgeryToken]
  50. public ActionResult Create([Bind(Include = "id,nombre,apellido,telefono")] comprador comprador)
  51. {
  52. if (ModelState.IsValid)
  53. {
  54. db.comprador.Add(comprador);
  55. db.SaveChanges();
  56. return RedirectToAction("Index");
  57. }
  58.  
  59. return View(comprador);
  60. }
  61.  
  62. // GET: Comprador/Edit/5
  63. public ActionResult Edit(int? id)
  64. {
  65. if (id == null)
  66. {
  67. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  68. }
  69. comprador comprador = db.comprador.Find(id);
  70. if (comprador == null)
  71. {
  72. return HttpNotFound();
  73. }
  74. return View(comprador);
  75. }
  76.  
  77. // POST: Comprador/Edit/5
  78. // Para protegerse de ataques de publicación excesiva, habilite las propiedades específicas a las que desea enlazarse. Para obtener
  79. // más información vea http://go.microsoft.com/fwlink/?LinkId=317598.
  80. [HttpPost]
  81. [ValidateAntiForgeryToken]
  82. public ActionResult Edit([Bind(Include = "id,nombre,apellido,telefono")] comprador comprador)
  83. {
  84. if (ModelState.IsValid)
  85. {
  86. db.Entry(comprador).State = EntityState.Modified;
  87. db.SaveChanges();
  88. return RedirectToAction("Index");
  89. }
  90. return View(comprador);
  91. }
  92.  
  93. // GET: Comprador/Delete/5
  94. public ActionResult Delete(int? id)
  95. {
  96. if (id == null)
  97. {
  98. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  99. }
  100. comprador comprador = db.comprador.Find(id);
  101. if (comprador == null)
  102. {
  103. return HttpNotFound();
  104. }
  105. return View(comprador);
  106. }
  107.  
  108. // POST: Comprador/Delete/5
  109. [HttpPost, ActionName("Delete")]
  110. [ValidateAntiForgeryToken]
  111. public ActionResult DeleteConfirmed(int id)
  112. {
  113. comprador comprador = db.comprador.Find(id);
  114. try
  115. {
  116. db.comprador.Remove(comprador);
  117. db.SaveChanges();
  118. return RedirectToAction("Index");
  119. }
  120. catch
  121. {
  122. ViewBag.Error = "No se puede eliminar debido a que existen datos asociados";
  123. }
  124. return View(comprador);
  125.  
  126. }
  127.  
  128. protected override void Dispose(bool disposing)
  129. {
  130. if (disposing)
  131. {
  132. db.Dispose();
  133. }
  134. base.Dispose(disposing);
  135. }
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement