Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. @model Company
  2.  
  3. @{
  4. Layout = "~/Views/Shared/_Layout.cshtml";
  5. }
  6. @using (Html.BeginForm())
  7. {
  8. <div class="jumboservice">
  9. <div data-role="page">
  10. <div data-role="header">
  11. <h2>PA IPv4 Request Form</h2>
  12. </div>
  13. <div class="ui-content" data-role="main">
  14. <h3>Company Details</h3>
  15. <div class="ui-grid-c ui-responsive">
  16. <div class="ui-block-a">
  17. <p class="lblStyle">Company Name</p>
  18. <span>
  19. @Html.EditorFor(m => m.name)
  20. @Html.ValidationMessageFor(m => m.name)
  21. </span>
  22. </div>
  23. </div>
  24. </div>
  25. <br />
  26. @foreach (var i in Model.pa_ipv4s)
  27. {
  28. @Html.Partial("Pa_IPv4View", i)
  29. }
  30. <br />
  31. <div data-role="main" class="ui-content">
  32. <div data-role="controlgroup" data-type="horizontal">
  33. <input type="submit" class="ui-btn" value="Create" />
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. }
  39. <script type="text/javascript">
  40. $(function () {
  41. $('#addItemRIpM').on('click', function () {
  42. $.ajax({
  43. url: '@Url.Action("RequestedManager")',
  44. cache: false,
  45. success: function (html) { $("#editorRowsRIpM").append(html); }
  46. });
  47. return false;
  48. });
  49. $('#editorRowsRIpM').on('click', '.deleteRow', function () {
  50. $(this).closest('.editorRow').remove();
  51. });
  52. });
  53. </script>
  54.  
  55. @model Pa_Ipv4
  56.  
  57. @using (HtmlHelpers.BeginCollectionItem.HtmlPrefixScopeExtensions.BeginCollectionItem(Html,"pa_ipv4s"))
  58. {
  59. @Html.AntiForgeryToken()
  60. <div class="ui-grid-c ui-responsive">
  61. <div class="ui-block-a">
  62. <p class="lblStyle">Subnet</p>
  63. </div>
  64. <div class="ui-block-b">
  65. <p class="lblStyle">Size(CIDR)</p>
  66. </div>
  67. <div class="ui-block-c">
  68. <p class="lblStyle">Mask</p>
  69. </div>
  70. <div class="ui-block-d">
  71. </div>
  72. </div>
  73. @*Request IP Address Space List*@
  74. <div id="editorRowsRIpM">
  75. @foreach (var item in Model.requestedIps)
  76. {
  77. @Html.Partial("RequestedIpView", item)
  78. }
  79. </div>
  80. @Html.ActionLink("Add", "RequestedManager", null, new { id = "addItemRIpM", @class = "button" })
  81. }
  82.  
  83. @model IpAllocation
  84.  
  85. <div class="editorRow">
  86. @using (HtmlHelpers.BeginCollectionItem.HtmlPrefixScopeExtensions.BeginCollectionItem(Html, "requestedIps"))
  87. {
  88. <div class="ui-grid-c ui-responsive">
  89. <div class="ui-block-a">
  90. <span>
  91. @Html.TextBoxFor(m => m.subnet)
  92. </span>
  93. </div>
  94. <div class="ui-block-b">
  95. <span>
  96. @Html.TextBoxFor(m => m.cidr)
  97. </span>
  98. </div>
  99. <div class="ui-block-c">
  100. <span>
  101. @Html.TextBoxFor(m => m.mask)
  102. <span class="dltBtn">
  103. <a href="#" class="deleteRow">Remove</a>
  104. </span>
  105. </span>
  106. </div>
  107. </div>
  108. }
  109. </div>
  110.  
  111. public ActionResult Create()
  112. {
  113. var cmp = new Company();
  114. cmp.contacts = new List<Contact>
  115. {
  116. new Contact { email = "", name = "", telephone = "" }
  117. };
  118. cmp.pa_ipv4s = new List<Pa_Ipv4>
  119. {
  120. new Pa_Ipv4
  121. {
  122. ipType = "Pa_IPv4", registedAddress = false, existingNotes = "",
  123. numberOfAddresses = 0, returnedAddressSpace = false, additionalInformation = "",
  124. requestedIps = new List<IpAllocation>
  125. {
  126. new IpAllocation { allocationType = "Requested", cidr = "", mask = "", subnet = "" } // allocationType is null in cmp in the Create[HttpPost]
  127. }
  128. }
  129. };
  130.  
  131. return View(cmp);
  132. }
  133.  
  134. public ActionResult Pa_IPv4Manager()
  135. {
  136. return PartialView("Pa_IPv4View", new Pa_Ipv4());
  137. }
  138. public ActionResult RequestedManager()
  139. {
  140. return PartialView("RequestedIpView", new IpAllocation { allocationType = "Requested" }); // allocationType is null in cmp in the Create[HttpPost]
  141. }
  142.  
  143. // POST: Pa_Ipv4/Create
  144. [HttpPost]
  145. [ValidateAntiForgeryToken]
  146. public ActionResult Create(Company cmp) //only one requestedIps count regardless of how many add
  147. {
  148. if (ModelState.IsValid)
  149. {
  150. db.companys.Add(cmp);
  151. db.SaveChanges();
  152. return RedirectToAction("Index");
  153. }
  154.  
  155. [Table("Ipv_Base")]
  156. public class Ipv_Base
  157. {
  158. [Key]
  159. public int ipv_baseId { get; set; }
  160. public int companyId { get; set; }
  161. [ForeignKey("companyId")]
  162. public Company company { get; set; }
  163. public string ipType { get; set; }
  164. [Required]
  165. public bool registedAddress { get; set; }
  166. [Required]
  167. [DataType(DataType.MultilineText)]
  168. public string existingNotes { get; set; }
  169. [Required]
  170. public int numberOfAddresses { get; set; }
  171. [Required]
  172. public bool returnedAddressSpace { get; set; }
  173. [DataType(DataType.MultilineText)]
  174. public string additionalInformation { get; set; }
  175. // navigation properties
  176. public virtual IList<IpAllocation> requestedIps { get; set; }
  177. }
  178. [Table("Company")]
  179. public class Company
  180. {
  181. [Key]
  182. public int companyId { get; set; }
  183. [Required]
  184. public string name { get; set; }
  185. [Required]
  186. public string telephone { get; set; }
  187. [Required]
  188. public string regNumber { get; set; }
  189. // navigation properties to keep track of the models that belong to the company
  190. public virtual IList<Pa_Ipv4> pa_ipv4s { get; set; }
  191.  
  192. }
  193. [Table("IpAllocation")]
  194. public class IpAllocation
  195. {
  196. [Key]
  197. public int ipAllocationId { get; set; }
  198. public int ipv_BaseId { get; set; }
  199. [ForeignKey("ipv_BaseId")]
  200. public Ipv_Base ipv_Base { get; set; }
  201. [Required]
  202. public string allocationType { get; set; }
  203. [Required]
  204. public string subnet { get; set; }
  205. [Required]
  206. public string cidr { get; set; }
  207. [Required]
  208. public string mask { get; set; }
  209. }
  210. public class Pa_Ipv4 : Ipv_Base
  211. {
  212. public Pa_Ipv4()
  213. {
  214. ipType = "pa_ipv4";
  215. }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement