Dear All.
I am trying to build a User authentication in ASP.Net MVC4 from a tutorial. I am already done with 80 % of the project but at the end i have faced with a problem. I couldn't get a clue even googling for an hour.
I have a user control just like below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Data.EntityModel;
using System.Data.Entity;
using System.Data.EntityClient;
using System.Data.OracleClient;
using System.Data.Objects.SqlClient;
namespace SimplyLogInSystem.Controllers
{
public class UserController : Controller
{
private object sysUser;
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult LogIn()
{
return View();
}
[HttpPost]
public ActionResult LogIn(Models.UserModel user)
{
if (ModelState.IsValid)
{
if (IsValid(user.Email, user.Password))
{
FormsAuthentication.SetAuthCookie(user.Email, false);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Login data is incorrect.");
}
}
return View(user);
}
[HttpGet]
public ActionResult Registration()
{
return View();
}
[HttpPost]
public ActionResult Registration(Models.UserModel user)
{
if (ModelState.IsValid)
{
using (var db = new MainDbContext())
{
var crypto = new SimpleCrypto.PBKDF2();
var encrpPass = crypto.Compute(user.Password);
var sysUsers = SystemUser.CreateSystemUser(Guid.NewGuid(), user.Email, encrpPass, crypto.Salt);
var sysUser = db.SystemUsers.Create();
db.SaveChanges();
return RedirectToAction ("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "Registration data is incorrect.");
}
return View();
}
and i have a model and a view for it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace SimplyLogInSystem.Models
{
public class UserModel
{
[Required]
[StringLength(50)]
[DataType(DataType.EmailAddress)]
[Display(Name="Email Address:")]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[StringLength(20, MinimumLength = 6)]
[Display(Name = "Password:")]
public string Password { get; set; }
}
}
The problem i am facing is that when i want to create the System User it ask for reference of .Create() which i don't have a clue on that. Can you help me with that as I am new to MVC and entity framework?