Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProjectInfo.ViewModels;
using ProjectDeInovacao.Models;
using ProjectInfo.Classes;
namespace ProjectInnovative.Controllers
{
public class HomeController: Controller
{
CadastroBLL bll = new CadastroBLL();
[HttpGet]
public ActionResult Login()
{
return View();
}
// instancia e manda valores para variaveis
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(Cadastro model)
{
if (ModelState.IsValid)
{
ViewData["Nome"] = model.Nome;
ViewData["Email"] = model.Email;
ViewData["Senha"] = model.Senha;
bll.cadastrar(model);
ModelState.Clear();
return View(model);
}
else
{
return View("Login");
}
}
public ActionResult Index()
{
ViewBag.Title = "Amorelli - Home";
return View();
}
public ActionResult Carrinho()
{
ViewBag.Title = "Amorelli - Carrinho";
return View();
}
}
}
Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace ProjectInnovative.Models
{
public class Registration
{
private string name;
[Required (ErrorMessage="Required to enter name")]
public string Name
{
get {return name; }
set {name = value; }
}
private string email;
[Required (ErrorMessage="Required E-mail")]
[RegularExpression (". + \ @. + \ .. +", ErrorMessage="The E-mail entered is not valid")]
public string Email
{
get {return email; }
set {email = value; }
}
private string password;
[Required (ErrorMessage="Required to enter a password")]
[DataType (DataType.Password)]
[StringLength (20, MinimumLength = 8)]
public string Password
{
get {return password; }
set {password = value; }
}
}
}
View:
@modelModels.CadastroDevelopment.model
@ {
ViewBag.Title="Amorelli - Login";
}
/*PARA VALIDAÇÃO DOS HELPERS*/
.field-validation-error {
color: #f00;
}
.field-validation-valid {
display: none;
}
.input-validation-error {
border: 1px solid #f00;
background-color: #fee;
}
.validation-summary-errors {
font-weight: bold;
color: #b94a48;
}
.validation-summary-valid {
display: none;
}
Log in to your account
Keep me connected
Login
OR
Sign up!
@using (Html.BeginForm ("Login", "Home"))
{
@Html.AntiForgeryToken ();
@Html.TextBoxFor (Model => Model.Name, new {id="Name", placeholder="Full Name"})
@ Html.TextBoxFor (Model => Model.Email, new {id="Email1", placeholder="Email"})
@ Html.TextBoxFor (Model => Template.Senha, new {id="Password1", placeholder="Password", type="password"})
Register
Home
@Html.ValidationSummary (false, "Please correct the errors below:")
}
(form login still being created)