public int CreateItem(string insertedDic, string type) { //return the id back to the JS Datatable! switch (type) { case "tbl_userdata": tbl_userdata newUser = JsonConvert.DeserializeObject <tbl_userdata>(insertedDic); //Check if the email has been taken already int emailIsTaken = MollShopContext.CheckIfUserExists(newUser.fld_email); if (emailIsTaken == 0) { //Email has not yet been taken //Salt and Hash the password newUser.fld_password = MollShopContext.SaltNHash(newUser.fld_password); newUser.fld_userid = MollShopContext.CreateRow(newUser, type); if (newUser.fld_dateofbirth == "") { newUser.fld_dateofbirth = null; } EsUpdater <tbl_userdata> .InsertDocument(newUser, "moll_users", "User", newUser.fld_userid.ToString()); return(newUser.fld_userid); } else { //Email has been taken return(-1); } case "tbl_servicedata": tbl_servicedata newService = JsonConvert.DeserializeObject <tbl_servicedata>(insertedDic); newService.fld_serviceid = MollShopContext.CreateRow(newService, type); EsUpdater <tbl_servicedata> .InsertDocument(newService, "moll_dataservices", "Services", newService.fld_serviceid.ToString()); return(newService.fld_serviceid); case "tbl_labourerdata": tbl_labourerdata newLabourer = JsonConvert.DeserializeObject <tbl_labourerdata>(insertedDic); newLabourer.fld_labourerid = MollShopContext.CreateRow(newLabourer, type); EsUpdater <tbl_labourerdata> .InsertDocument(newLabourer, "moll_labourers", "Labourer", newLabourer.fld_labourerid.ToString()); return(newLabourer.fld_labourerid); default: break; } return(0); }
public IActionResult DoRegister(string UserName, string Password, string FirstName, string LastName, string GenderValue, string Adres, string ZipCode, string DOB, string Phone, string Email) { tbl_userdata user = new tbl_userdata(); user.fld_username = UserName; user.fld_password = Password; user.fld_firstname = FirstName; user.fld_lastname = LastName; user.fld_gender = GenderValue; user.fld_address = Adres; user.fld_zipcode = ZipCode; user.fld_dateofbirth = DOB; user.fld_phonenumber = Phone; user.fld_email = Email; int emailIsTaken = MollShopContext.CheckIfUserExists(user.fld_email); if (emailIsTaken == 0) { int userNameExistance = MollShopContext.CheckIfUserNameIsTaken(user.fld_username); switch (userNameExistance) { case 0: user.fld_adminPriv = "N"; string activationToken = MollShopContext.RegisterNewUser(user); if (activationToken == "Db Error!") { ViewData["message"] = "Something went wrong on our end. Please contact support."; break; } SendVerificationLink(activationToken, user.fld_email); return(View("Login", new LoginModel())); case 1: ViewData["message"] = "This user name is already in use!"; break; default: ViewData["message"] = "Something went wrong on our end. Please contact support."; break; } return(View("Register", user)); } else { ViewData["message"] = "This email address has already been registered"; return(View("Register", user)); } }
public IActionResult Register(string UserName, string Password, string FirstName, string LastName, string GenderValue, string Adres, string ZipCode, string DOB, string Phone, string Email) { User user = new User(UserName, Password, FirstName, LastName, GenderValue, Adres, ZipCode, DOB, Phone, Email); LoginModel loginMdl = new LoginModel(Email, Password); MollShopContext context = HttpContext.RequestServices.GetService(typeof(TestWebApp.Models.MollShopContext)) as MollShopContext; int userExists = context.CheckIfUserExists(loginMdl); if (userExists == 0) { context.RegisterNewUser(user); return(RedirectToAction("LI_index", "Page")); } return(View()); }