Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. public ActionResult Register()
  2. {
  3. CDraguseniDBEntities dbContext = new CDraguseniDBEntities();
  4. IEnumerable<SelectListItem> items = dbContext.Users.Select(c => new SelectListItem
  5. {
  6.  
  7. Value=c.RoleID,
  8. Text =c.RoleID.ToString()
  9.  
  10. });
  11. ViewBag.RoleID = items;
  12. return View();
  13. }
  14.  
  15. @model ExamenBudescuMarius_2emeSes.Models.UserModel
  16.  
  17. @{
  18. ViewBag.Title = "Register";
  19. Layout = "~/Views/Shared/_Layout.cshtml";
  20. }
  21.  
  22. <h2>Register</h2>
  23.  
  24. @using (Html.BeginForm()) {
  25. @Html.AntiForgeryToken()
  26. @Html.ValidationSummary(true)
  27.  
  28. <fieldset>
  29. <legend>UserModel</legend>
  30.  
  31.  
  32. <div class="editor-label">
  33. @Html.LabelFor(model => model.RoleID)
  34. </div>
  35. <div class="editor-field">
  36. @Html.EditorFor(model => model.RoleID)
  37. @Html.ValidationMessageFor(model => model.RoleID)
  38. </div>
  39.  
  40. <div>
  41. <p>Role ID</p>
  42. @Html.DropDownListFor(model => model.RoleID, ViewBag.RoleID as IEnumerable<SelectListItem>, "-Select a value-", new { @class = "dropDown" })
  43. </div>
  44.  
  45. <div class="editor-label">
  46. @Html.LabelFor(model => model.FirstName)
  47. </div>
  48. <div class="editor-field">
  49. @Html.EditorFor(model => model.FirstName)
  50. @Html.ValidationMessageFor(model => model.FirstName)
  51. </div>
  52.  
  53. <div class="editor-label">
  54. @Html.LabelFor(model => model.LastName)
  55. </div>
  56. <div class="editor-field">
  57. @Html.EditorFor(model => model.LastName)
  58. @Html.ValidationMessageFor(model => model.LastName)
  59. </div>
  60.  
  61. <div class="editor-label">
  62. @Html.LabelFor(model => model.Email)
  63. </div>
  64. <div class="editor-field">
  65. @Html.EditorFor(model => model.Email)
  66. @Html.ValidationMessageFor(model => model.Email)
  67. </div>
  68.  
  69. <div class="editor-label">
  70. @Html.LabelFor(model => model.Username)
  71. </div>
  72. <div class="editor-field">
  73. @Html.EditorFor(model => model.Username)
  74. @Html.ValidationMessageFor(model => model.Username)
  75. </div>
  76.  
  77. <div class="editor-label">
  78. @Html.LabelFor(model => model.Password)
  79. </div>
  80. <div class="editor-field">
  81. @Html.EditorFor(model => model.Password)
  82. @Html.ValidationMessageFor(model => model.Password)
  83. </div>
  84.  
  85.  
  86. <div class="editor-label">
  87. @Html.LabelFor(model => model.ConfirmPassword)
  88. </div>
  89. <div class="editor-field">
  90. @Html.EditorFor(model => model.ConfirmPassword)
  91. @Html.ValidationMessageFor(model => model.ConfirmPassword)
  92. </div>
  93.  
  94. <p>
  95. <input type="submit" value="Create" />
  96. </p>
  97. </fieldset>
  98. }
  99.  
  100. <div>
  101. @Html.ActionLink("Back to List", "Index")
  102. </div>
  103.  
  104. @section Scripts {
  105. @Scripts.Render("~/bundles/jqueryval")
  106. }
  107.  
  108. using System;
  109. using System.Collections.Generic;
  110. using System.ComponentModel.DataAnnotations;
  111. using System.Linq;
  112. using System.Web;
  113. using System.Web.Mvc;
  114. using CompareAttribute = System.Web.Mvc.CompareAttribute;
  115.  
  116. namespace ExamenBudescuMarius_2emeSes.Models
  117. {
  118. public class UserModel
  119. {
  120. public int UserID { get; set; }
  121.  
  122. public string Username { get; set; }
  123.  
  124. [DataType(DataType.Password)]
  125. [StringLength(255, MinimumLength = 8)]
  126. public string Password { get; set; }
  127.  
  128. [Required(ErrorMessage = "Your Name is required")]
  129. [StringLength(50, ErrorMessage = "Your name must be maximum 50 letters.")]
  130. [Remote("UsernameExists", "Account", HttpMethod = "POST", ErrorMessage = "User name already registered.")]
  131. [Display(Name = "Name")]
  132. public string FirstName { get; set; }
  133.  
  134. [Required(ErrorMessage = "Your Last Name is required")]
  135. [StringLength(70, ErrorMessage = "Your name must be max 70 letters.")]
  136. [Display(Name = "Last Name")]
  137. public string LastName { get; set; }
  138.  
  139. [RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}", ErrorMessage = "Email doesn't look like a valid email address.")]
  140. [Remote("EmailExists", "Account", HttpMethod = "POST", ErrorMessage = "Email address already registered.")]
  141. [Display(Name = "Email")]
  142. public string Email { get; set; }
  143. public int RoleID { get; set; }
  144.  
  145. public virtual Roles Roles { get; set; }
  146.  
  147. [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
  148. [DataType(DataType.Password)]
  149. [StringLength(255, MinimumLength = 8)]
  150. public string ConfirmPassword { get; set; }
  151. }
  152. }
  153.  
  154. CREATE TABLE Roles(
  155. RoleID int identity(1,1) Primary key not null,
  156. RoleName varchar(50) not null
  157. );
  158. create table Users(
  159. UserID int identity(1,1) primary key not null,
  160. Username varchar(100) not null,
  161. [Password] varchar(120) not null,
  162. FirstName varchar(120) not null,
  163. LastName varchar(120) not null,
  164. Email varchar(120) not null,
  165. RoleID int not null,
  166. CONSTRAINT [FK_RoleIDRoles] FOREIGN KEY ([RoleID]) REFERENCES [dbo].[Roles] ([RoleID])
  167. );
  168.  
  169. create table Album(
  170. AlbumID int identity(1,1) primary key not null,
  171. AlbumName varchar(120) not null
  172. );
  173. create table Images(
  174. ImageID int identity(1,1) primary key not null,
  175. ImageName varchar(120) not null,
  176. ImagePath nvarchar(100) not null,
  177. ImageDescription varchar(max) ,
  178. AlbumID int,
  179. CONSTRAINT [FK_Images_Album] FOREIGN KEY ([AlbumID]) REFERENCES [dbo]. [Album] ([AlbumID])
  180. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement