Please help. I am new to web development and currently working on a razor web pages site. I have the name of the StarterSite.sdf changed to YourBookBroker.sdf along with adding the changes to the web.config, _AppStart, Register.cshtml, and RegisterService.cshtml for calling the database.
I have been unsuccessful trying to add data to a username column in the userprofile table so i made a "SiteUser" table with UserID, UserName, Password, FirstName, LastName, Address, City, State, PostalCode - columns. I added an additional insert statement below the insert for the userprofile insert. I also changed the form and added a username field. But I am getting "A duplicate value cannot be inserted into a unique index. [ Table name = SiteUsers,Constraint name = UQ__SiteUsers__00000000000000B9 ]" error. I'm not sure why this is happing. It looks like I am doing the exact same process as the insert statement for the userprofile.
This error comes up, but the email field is added to the UserProfile table. This error occurs when the username is trying to be added to my SiteUser table.
// If this is a POST request, validate and process data
if (IsPost) {
AntiForgery.Validate();
username = Request.Form["username"];
email = Request.Form["email"];
password = Request.Form["password"];
confirmPassword = Request.Form["confirmPassword"];
if (Validation.IsValid()) {
// Insert a new user into the database
var db = Database.Open("YourBookBroker");
var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);
if(user ==null) {
// Insert email into the profile table
db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);
db.Execute("INSERT SiteUsers (UserName) VALUES (@0)", username);
FORM
<liclass="username">
<labelfor="username">User Name</label>
<inputtype="text"id="username"name="username"value="@username"/>
</li>
<liclass="email">
<labelfor="email" @if(!ModelState.IsValidField("email")){<text>class="error-label"</text>}>Email address</label>
<inputtype="text"id="email"name="email"value="@email" @Validation.For("email")/>
@*Write any email validation errors to the page *@
@Html.ValidationMessage("email")
the rest of the form is the original register.cshtml page. I simply added the username portion. I would very much appreciate any help possible.