Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Register()
- {
- CDraguseniDBEntities dbContext = new CDraguseniDBEntities();
- IEnumerable<SelectListItem> items = dbContext.Users.Select(c => new SelectListItem
- {
- Value=c.RoleID,
- Text =c.RoleID.ToString()
- });
- ViewBag.RoleID = items;
- return View();
- }
- @model ExamenBudescuMarius_2emeSes.Models.UserModel
- @{
- ViewBag.Title = "Register";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
- <h2>Register</h2>
- @using (Html.BeginForm()) {
- @Html.AntiForgeryToken()
- @Html.ValidationSummary(true)
- <fieldset>
- <legend>UserModel</legend>
- <div class="editor-label">
- @Html.LabelFor(model => model.RoleID)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.RoleID)
- @Html.ValidationMessageFor(model => model.RoleID)
- </div>
- <div>
- <p>Role ID</p>
- @Html.DropDownListFor(model => model.RoleID, ViewBag.RoleID as IEnumerable<SelectListItem>, "-Select a value-", new { @class = "dropDown" })
- </div>
- <div class="editor-label">
- @Html.LabelFor(model => model.FirstName)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.FirstName)
- @Html.ValidationMessageFor(model => model.FirstName)
- </div>
- <div class="editor-label">
- @Html.LabelFor(model => model.LastName)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.LastName)
- @Html.ValidationMessageFor(model => model.LastName)
- </div>
- <div class="editor-label">
- @Html.LabelFor(model => model.Email)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.Email)
- @Html.ValidationMessageFor(model => model.Email)
- </div>
- <div class="editor-label">
- @Html.LabelFor(model => model.Username)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.Username)
- @Html.ValidationMessageFor(model => model.Username)
- </div>
- <div class="editor-label">
- @Html.LabelFor(model => model.Password)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.Password)
- @Html.ValidationMessageFor(model => model.Password)
- </div>
- <div class="editor-label">
- @Html.LabelFor(model => model.ConfirmPassword)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.ConfirmPassword)
- @Html.ValidationMessageFor(model => model.ConfirmPassword)
- </div>
- <p>
- <input type="submit" value="Create" />
- </p>
- </fieldset>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- @section Scripts {
- @Scripts.Render("~/bundles/jqueryval")
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using CompareAttribute = System.Web.Mvc.CompareAttribute;
- namespace ExamenBudescuMarius_2emeSes.Models
- {
- public class UserModel
- {
- public int UserID { get; set; }
- public string Username { get; set; }
- [DataType(DataType.Password)]
- [StringLength(255, MinimumLength = 8)]
- public string Password { get; set; }
- [Required(ErrorMessage = "Your Name is required")]
- [StringLength(50, ErrorMessage = "Your name must be maximum 50 letters.")]
- [Remote("UsernameExists", "Account", HttpMethod = "POST", ErrorMessage = "User name already registered.")]
- [Display(Name = "Name")]
- public string FirstName { get; set; }
- [Required(ErrorMessage = "Your Last Name is required")]
- [StringLength(70, ErrorMessage = "Your name must be max 70 letters.")]
- [Display(Name = "Last Name")]
- public string LastName { get; set; }
- [RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}", ErrorMessage = "Email doesn't look like a valid email address.")]
- [Remote("EmailExists", "Account", HttpMethod = "POST", ErrorMessage = "Email address already registered.")]
- [Display(Name = "Email")]
- public string Email { get; set; }
- public int RoleID { get; set; }
- public virtual Roles Roles { get; set; }
- [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
- [DataType(DataType.Password)]
- [StringLength(255, MinimumLength = 8)]
- public string ConfirmPassword { get; set; }
- }
- }
- CREATE TABLE Roles(
- RoleID int identity(1,1) Primary key not null,
- RoleName varchar(50) not null
- );
- create table Users(
- UserID int identity(1,1) primary key not null,
- Username varchar(100) not null,
- [Password] varchar(120) not null,
- FirstName varchar(120) not null,
- LastName varchar(120) not null,
- Email varchar(120) not null,
- RoleID int not null,
- CONSTRAINT [FK_RoleIDRoles] FOREIGN KEY ([RoleID]) REFERENCES [dbo].[Roles] ([RoleID])
- );
- create table Album(
- AlbumID int identity(1,1) primary key not null,
- AlbumName varchar(120) not null
- );
- create table Images(
- ImageID int identity(1,1) primary key not null,
- ImageName varchar(120) not null,
- ImagePath nvarchar(100) not null,
- ImageDescription varchar(max) ,
- AlbumID int,
- CONSTRAINT [FK_Images_Album] FOREIGN KEY ([AlbumID]) REFERENCES [dbo]. [Album] ([AlbumID])
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement