I am trying to insert data in my DB for registration and below is what I have inside my AccountController
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register(PersonLogin rd)
{
EBYSContext db = new EBYSContext();
if (ModelState.IsValid)
{
var kisi = new Person();
kisi.Adi = "Abdullah";
kisi.TcKimlikNo = "99565282133";
kisi.Soyadi = "Taher";
db.Persons.Add(kisi);
db.SaveChanges();
WebSecurity.CreateUserAndAccount(rd.Username, rd.Password, new
{
//KisiID = new PersonLogin(),
Username = rd.Username,
Password = rd.Password,
Email = rd.Email,
YanlisGirisSayisi = 1,
SifreDegistirilsin = false,
SonKullanimTarihi = new DateTime(2014, 1, 18),
SonGirisTarihi = new DateTime(2014, 1, 18),
SonSifreDegisimTarihi = new DateTime(2014, 1, 18),
});
return RedirectToAction("Login","Account");
}
ModelState.AddModelError("","Please check your credentials...");
return View(rd);
}
I have two two tables Person and PersonLogin. The later contain login information like NumberOfLoginAttempts(YanlisGirisSayisi ) etc. The two table has 1-1 relationship.
When I post the form I am able to insert the data in Person's table but later I get Cannot convert type 'System.Guid' to 'int'
, the error being pointing to
WebSecurity.CreateUserAndAccount(rd.Username, rd.Password, new
{
After a long research I came to realize that data for userIdColumn in WebSecurity.InitializeDatabaseConnection MUST be integer
. I have declared my userId (kisiID) column as uniqueIdentifier
in database. As far as I know it is impossible to convert System.Guid
to int
My question is how can I go about inserting a new row in PersonLogin table using the same ID created in Person table.
I know the question is little bit confusing but I hope I'll get something useful. By the way am using Entity framework Database First Approach.
Additonal Links: InitializeDatabaseConnection Method