Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. public class Club
  2. {
  3. // Class to manage a single Club
  4. [Key]
  5. public int ClubID { get; set; }
  6.  
  7. //Name
  8. [Required(ErrorMessage = "You must enter a Club Name")]
  9. [DataType(DataType.Text)]
  10. [StringLength(50, ErrorMessage = "Club Name cannot be longer than 50 characters")]
  11. [Display(Name = "Club Name")]
  12. public string ClubName { get; set; }
  13.  
  14. //Discription
  15. [Display(Name = "Description")]
  16. [StringLength(200, ErrorMessage = "Discription is too long")] //character remaining count
  17. public string ClubDescription { get; set; }
  18.  
  19. //Club Type
  20. public enum ClubType { Archery, Athletics, Basketball, Boxing, Camogie, Cricket, Cycling, Darts, Gaelic, Golf, Handball, Hocky, Hurling, Karate, MMA, Pool, Rugby, Snooker, Snowsports, Soccer, Surfing, Swimming, Tennis, Vollyball, Windsurfing, Youth, Other }
  21.  
  22. //List of Members that are members of this Club
  23. public virtual List<ClubMember> ClubMembers { get; set; }
  24.  
  25. //List of Events for this Club
  26. public virtual List<ClubEvent> ClubEvents { get; set; } //List of Events for this Club
  27.  
  28. public String ClubImage { get; set; }
  29.  
  30.  
  31. }//end Club
  32.  
  33. public class ClubMember
  34. {
  35. [Key]
  36. public int UserId { get; set; }
  37.  
  38. //First Name
  39. [Required(ErrorMessage = "You must enter a First Name")]
  40. [StringLength(50, ErrorMessage = "You have used too many characters")] //character remaining count
  41. [DataType(DataType.Text)]
  42. [Display(Name = "First Name")]
  43. public string UserFName { get; set; }
  44.  
  45. //Last Name
  46. [Required(ErrorMessage = "You must enter a Last Name")]
  47. [StringLength(50, ErrorMessage = "You have used too many characters")] //character remaining count
  48. [DataType(DataType.Text)]
  49. [Display(Name = "Last Name")]
  50. public string UserLName { get; set; }
  51.  
  52. //User Name
  53. [Required(ErrorMessage = "You must enter a User Name")]
  54. [DataType(DataType.Text)]
  55. [Display(Name = "User Name")]
  56. public string UserName { get; set; }
  57.  
  58. //Email
  59. [Required(ErrorMessage = "You must enter an Email Address")]
  60. [RegularExpression(@"^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$", ErrorMessage = "Please enter a valid email address")]
  61. [StringLength(50, ErrorMessage = "You have used too many characters")] //character remaining count
  62. [Display(Name = "Email")]
  63. public string UserEmail { get; set; }
  64.  
  65. //Description
  66. [Display(Name = "User Description")]
  67. [StringLength(200, ErrorMessage = "You have used too many characters")] //character remaining count
  68. public string UserDescription { get; set; }
  69.  
  70. //Date Of Brith
  71. [Required(ErrorMessage = "You must select your Date Of Birth")]
  72. [Display(Name = "Date of Birth")]
  73. public DateTime UserDoB { get; set; }
  74.  
  75. //Image
  76. public string UserImage { get; set; }
  77.  
  78. //Password
  79. //[Required]
  80. [StringLength(20, MinimumLength = 6)]
  81. public string UserPassword { get; set; }
  82.  
  83. //Foreign Key for Club
  84. public int ClubID { get; set; }
  85.  
  86. [ForeignKey("ClubID")]
  87. public virtual Club Club { get; set; }
  88. }//end User Class
  89.  
  90. {
  91. if (id == null)
  92. {
  93. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  94. }
  95. Club club = db.Clubs.Find(id);
  96. if (club == null)
  97. {
  98. return HttpNotFound();
  99. }
  100. return View(club);
  101. }
  102.  
  103. [HttpPost]
  104. [ValidateAntiForgeryToken]
  105. public ActionResult Edit([Bind(Include = "ClubID,ClubName,ClubDescription,ClubMembers")] Club club)
  106. {
  107. if (ModelState.IsValid)
  108. {
  109. db.Entry(club).State = EntityState.Modified;
  110. db.SaveChanges();
  111. return RedirectToAction("Index");
  112. }
  113. return View(club);
  114. }
  115.  
  116. @model ultimateorganiser.Models.Club
  117.  
  118. @{
  119. ViewBag.Title = "Edit";
  120. }
  121.  
  122. <h2>Edit</h2>
  123.  
  124. @using (Html.BeginForm())
  125. {
  126. @Html.AntiForgeryToken()
  127.  
  128. <div class="form-horizontal">
  129. <h4>Club</h4>
  130. <hr />
  131. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  132. @Html.HiddenFor(model => model.ClubID)
  133.  
  134. <div class="form-group">
  135. @Html.LabelFor(model => model.ClubName, htmlAttributes: new { @class = "control-label col-md-2" })
  136. <div class="col-md-10">
  137. @Html.EditorFor(model => model.ClubName, new { htmlAttributes = new { @class = "form-control" } })
  138. @Html.ValidationMessageFor(model => model.ClubName, "", new { @class = "text-danger" })
  139. </div>
  140. </div>
  141.  
  142. <div class="form-group">
  143. @Html.LabelFor(model => model.ClubDescription, htmlAttributes: new { @class = "control-label col-md-2" })
  144. <div class="col-md-10">
  145. @Html.EditorFor(model => model.ClubDescription, new { htmlAttributes = new { @class = "form-control" } })
  146. @Html.ValidationMessageFor(model => model.ClubDescription, "", new { @class = "text-danger" })
  147. </div>
  148. </div>
  149.  
  150.  
  151. @*This is where I want to display each club member in a list*@
  152. @foreach (var item in Model.ClubMembers)
  153. {
  154. <div class="form-group">
  155. @Html.LabelFor(model => model.ClubMembers, htmlAttributes: new { @class = "control-label col-md-2" })
  156. <div class="col-md-10">
  157. @Html.EditorFor(model => model.ClubMembers, new { htmlAttributes = new { @class = "form-control" } })
  158. @Html.ValidationMessageFor(model => model.ClubMembers, "", new { @class = "text-danger" })
  159. </div>
  160. </div>
  161. }
  162.  
  163. <div class="form-group">
  164. <div class="col-md-offset-2 col-md-10">
  165. <input type="submit" value="Save" class="btn btn-default" />
  166. </div>
  167. </div>
  168. </div>
  169. }
  170.  
  171. <div>
  172. @Html.ActionLink("Back to List", "Index")
  173. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement