Guest User

Untitled

a guest
Jul 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. public class Policy
  2. {
  3. public List<PolicyLine> PolicyLines = new List<PolicyLine>();
  4. }
  5.  
  6. public class PolicyLine
  7. {
  8. public PolicyLine(bool isPositive, string policyText)
  9. {
  10. IsPositive = isPositive;
  11. PolicyText = policyText;
  12. }
  13.  
  14. public bool IsPositive { get; set; }
  15.  
  16. public string PolicyText { get; set; }
  17. }
  18.  
  19. @Html.ActionLink("Delete", "Delete", new { id = @Model.PolicyID })
  20.  
  21. @using (Html.BeginForm("Submit", "Policy")) {
  22. <fieldset>
  23. @Html.EditorForModel()
  24. </fieldset>
  25. }
  26.  
  27. @model Policy
  28. <br />
  29. <label for="IsPositive">Is positive?</label>
  30. @Html.CheckBox("IsPositive")
  31. <input type="text" name="PolicyText" />
  32. <input type="submit" value="Add to Policy" title="SubmitFromReferalPolicy" />
  33. @Html.EditorFor(a => a.PolicyLines)
  34.  
  35. @model PolicyLine
  36. <br />
  37. @this.Model.ToString()
  38. @Html.ActionLink("Delete", "DeleteLine/" + Model.Identifier.ToString())
  39.  
  40. public class Policy
  41. {
  42. public string Id { get; set; }
  43.  
  44. public List<PolicyLine> PolicyLines = new List<PolicyLine>();
  45.  
  46. public override string ToString()
  47. {
  48. return PolicyFormatter.FormatPolicy(this);
  49. }
  50. }
  51.  
  52. public class PolicyLine
  53. {
  54. public bool IsPositive { get; set; }
  55.  
  56. public string PolicyText { get; set; }
  57.  
  58. public Guid Identifier { get; set; }
  59.  
  60. public override string ToString()
  61. {
  62. return PolicyFormatter.FormatPolicyLine(this);
  63. }
  64. }
  65.  
  66. [HttpPost]
  67. public ActionResult Submit(PolicyLine submitted)
  68. {
  69. Policy saveMe = Policy.GetPolicyFromUserName(UserName);
  70. submitted.Identifier = Guid.NewGuid();
  71. saveMe.PolicyLines.Add(submitted);
  72. Store.Write(saveMe);
  73.  
  74. return RedirectToAction("Index");
  75. }
  76.  
  77. public ActionResult DeleteLine(Guid identifier)
  78. {
  79. Policy saveMe = Policy.GetPolicyFromUserName(UserName);
  80. PolicyLine removeMe = saveMe.PolicyLines.Find(p => p.Identifier == identifier);
  81. saveMe.PolicyLines.Remove(removeMe);
  82. Store.Write(saveMe);
  83. return RedirectToAction("Index");
  84. }
Add Comment
Please, Sign In to add comment