public ActionResult Register(RegisterModel newUser) { if (!ModelState.IsValid || !VerificationHelper.IsUsernameAvailable(newUser.Username)) { ViewBag.UsedName = "Korisničko ime se već koristi"; return(View()); } var hashedPass = EncodingHelper.Encode(newUser.Password); newUser.Password = hashedPass; // Add new user account to tblAccount var entityData = ModelToEntityMapper.ConvertToEntity <TblAccount, RegisterModel>(newUser); var repo = new Repository <TblAccount>(new DatabaseEntities()); repo.Add(entityData); // Get new user ID from TblAccount and.... var getNewAccRepo = new Repository <TblAccount>(new DatabaseEntities()); var newId = getNewAccRepo.SingleOrDefault(q => q.Username == newUser.Username).Id; // ...add it initially into TblUser var insertNewUidUserRepo = new Repository <TblUser>(new DatabaseEntities()); insertNewUidUserRepo.Add(new TblUser { UserId = newId }); // ...add it initially into TblExtras var insertNewUidExpRepo = new Repository <TblExtras>(new DatabaseEntities()); insertNewUidExpRepo.Add(new TblExtras { UserId = newId }); // Create session and auth cookie CookieHepler.SetUidCookie(newId); FormsAuthentication.SetAuthCookie(newUser.Username, false); repo.Dispose(); return(RedirectToAction("Index", "Home")); }