Guest User

Untitled

a guest
Nov 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. @{
  2. ViewBag.Title = "Index";
  3. }
  4.  
  5. <ul class="nav nav-tabs">
  6. <li class="active"><a data-toggle="tab" href="#firstTab">View All
  7. Vendors</a></li>
  8. <li><a data-toggle="tab" href="#secondTab">Add New</a></li>
  9. <li><a data-toggle="tab" href="#thirdTab">Remove</a></li>
  10. </ul>
  11. <div class="tab-content">
  12. <div id="firstTab" class="tab-pane fade in active">@Html.Action("ViewAll")</div>
  13. <div id="secondTab" class="tab-pane fade in">@Html.Action("AddOrEdit")</div>
  14. <div id="thirdTab" class="tab-pane fade in">tab 3 content</div>
  15. </div>
  16. @section scripts
  17. {
  18. @Scripts.Render("~/bundles/jqueryval")
  19. }
  20.  
  21. @model VendorApp.Models.VENDOR
  22.  
  23. @{
  24. ViewBag.Title = "AddOrEdit";
  25. }
  26.  
  27. @using (Html.BeginForm("AddOrEdit","Vendor",FormMethod.Post, new { enctype = "multipart/form-data", onSubmit = "return jQueryAjaxPost(this);" }))
  28. {
  29. @Html.AntiForgeryToken()
  30. <div class="row">
  31. <div class="form-horizontal">
  32. <h4>Add Vendor</h4>
  33. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  34. @Html.HiddenFor(model => model.VENDOR_NUM)
  35.  
  36. <div class="col-md-6">
  37. <div class="form-group">
  38. @Html.LabelFor(model => model.VENDOR_NAME, htmlAttributes: new { @class = "control-label col-md-2" })
  39. <div class="col-md-10">
  40. @Html.EditorFor(model => model.VENDOR_NAME, new { htmlAttributes = new { @class = "form-control" } })
  41. @Html.ValidationMessageFor(model => model.VENDOR_NAME, "", new { @class = "text-danger" })
  42. </div>
  43. </div>
  44.  
  45. <div class="form-group">
  46. @Html.LabelFor(model => model.STREET, htmlAttributes: new { @class = "control-label col-md-2" })
  47. <div class="col-md-10">
  48. @Html.EditorFor(model => model.STREET, new { htmlAttributes = new { @class = "form-control" } })
  49. @Html.ValidationMessageFor(model => model.STREET, "", new { @class = "text-danger" })
  50. </div>
  51. </div>
  52.  
  53. <div class="form-group">
  54. @Html.LabelFor(model => model.CITY, htmlAttributes: new { @class = "control-label col-md-2" })
  55. <div class="col-md-10">
  56. @Html.EditorFor(model => model.CITY, new { htmlAttributes = new { @class = "form-control" } })
  57. @Html.ValidationMessageFor(model => model.CITY, "", new { @class = "text-danger" })
  58. </div>
  59. </div>
  60.  
  61. <div class="form-group">
  62. @Html.LabelFor(model => model.STATE, htmlAttributes: new { @class = "control-label col-md-2" })
  63. <div class="col-md-10">
  64. @Html.EditorFor(model => model.STATE, new { htmlAttributes = new { @class = "form-control" } })
  65. @Html.ValidationMessageFor(model => model.STATE, "", new { @class = "text-danger" })
  66. </div>
  67. </div>
  68. <div class="form-group">
  69. <div class="col-md-offset-2 col-md-10">
  70. <input type="submit" value="Update" class="btn btn-default" />
  71. </div>
  72. </div>
  73. </div>
  74. <div class="col-md-6">
  75. <div class="form-group">
  76. @Html.LabelFor(model => model.ZIP, htmlAttributes: new { @class = "control-label col-md-2" })
  77. <div class="col-md-10">
  78. @Html.EditorFor(model => model.ZIP, new { htmlAttributes = new { @class = "form-control" } })
  79. @Html.ValidationMessageFor(model => model.ZIP, "", new { @class = "text-danger" })
  80. </div>
  81. </div>
  82.  
  83. <div class="form-group">
  84. @Html.LabelFor(model => model.PHONE, htmlAttributes: new { @class = "control-label col-md-2" })
  85. <div class="col-md-10">
  86. @Html.EditorFor(model => model.PHONE, new { htmlAttributes = new { @class = "form-control" } })
  87. @Html.ValidationMessageFor(model => model.PHONE, "", new { @class = "text-danger" })
  88. </div>
  89. </div>
  90.  
  91. <div class="form-group">
  92. @Html.LabelFor(model => model.EMAIL, htmlAttributes: new { @class = "control-label col-md-2" })
  93. <div class="col-md-10">
  94. @Html.EditorFor(model => model.EMAIL, new { htmlAttributes = new { @class = "form-control" } })
  95. @Html.ValidationMessageFor(model => model.EMAIL, "", new { @class = "text-danger" })
  96. </div>
  97. </div>
  98.  
  99. <div class="form-group">
  100. @Html.LabelFor(model => model.SERVICE, htmlAttributes: new { @class = "control-label col-md-2" })
  101. <div class="col-md-10">
  102. @Html.EditorFor(model => model.SERVICE, new { htmlAttributes = new { @class = "form-control" } })
  103. @Html.ValidationMessageFor(model => model.SERVICE, "", new { @class = "text-danger" })
  104. </div>
  105. </div>
  106.  
  107. <div class="form-group">
  108. @Html.LabelFor(model => model.NOTE, htmlAttributes: new { @class = "control-label col-md-2" })
  109. <div class="col-md-10">
  110. @Html.EditorFor(model => model.NOTE, new { htmlAttributes = new { @class = "form-control" } })
  111. @Html.ValidationMessageFor(model => model.NOTE, "", new { @class = "text-danger" })
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. }
  118.  
  119. using System;
  120. using System.Collections.Generic;
  121. using System.Data.Entity.Infrastructure;
  122. using System.Linq;
  123. using System.Web;
  124. using System.Web.Mvc;
  125. using VendorApp.Models;
  126.  
  127. namespace VendorApp.Controllers
  128. {
  129. public class VendorController : Controller
  130. {
  131. // GET: Vendor
  132. public ActionResult Index()
  133. {
  134. return View();
  135. }
  136.  
  137. //get all Vendors
  138. public ActionResult ViewAll()
  139. {
  140. return View(GetAllVendor());
  141. }
  142.  
  143. //numerate the vendors
  144.  
  145. IEnumerable<VENDOR>GetAllVendor()
  146. {
  147. using (Pref_VendorEntities db = new Pref_VendorEntities())
  148. {
  149. return db.VENDORs.ToList<VENDOR>();
  150. }
  151. }
  152.  
  153. /// <summary>
  154. /// HTTP GET by DEFAULT
  155. /// </summary>
  156. /// <returns></returns>
  157. public ActionResult AddOrEdit()
  158. {
  159. VENDOR vendor = new VENDOR();
  160. return View(vendor);
  161. }
  162.  
  163. /// <summary>
  164. /// HTTP Post
  165. /// </summary>
  166. /// <returns></returns>
  167.  
  168. [HttpPost]
  169. public ActionResult AddOrEdit(VENDOR vend)
  170. {
  171. using (Pref_VendorEntities db = new Pref_VendorEntities())
  172. {
  173. db.VENDORs.Add(vend);
  174. db.SaveChanges();
  175. }
  176.  
  177. return RedirectToAction("ViewAll");
  178. }
  179. }
  180. }
Add Comment
Please, Sign In to add comment