public void RegisterUser(RegisterDO form) { SqlConnection connectionToSql = null; SqlCommand storedProcedure = null; try { connectionToSql = new SqlConnection(_connectionString); storedProcedure = new SqlCommand("USER_REGISTER", connectionToSql); storedProcedure.CommandType = System.Data.CommandType.StoredProcedure; storedProcedure.Parameters.AddWithValue("@Username", form.Username); storedProcedure.Parameters.AddWithValue("@Password", form.Password); storedProcedure.Parameters.AddWithValue("@Email", form.Email); storedProcedure.Parameters.AddWithValue("@Name", form.Name); connectionToSql.Open(); storedProcedure.ExecuteNonQuery(); } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); throw ex; } finally { if (connectionToSql != null) { connectionToSql.Close(); connectionToSql.Dispose(); } } }
public static RegisterPO RegisterDOToPO(RegisterDO from) { RegisterPO to = new RegisterPO(); to.Username = from.Username; to.Password = from.Password; to.Email = from.Email; to.Name = from.Name; return(to); }
public ActionResult Register(RegisterPO form) { ActionResult response = null; if (ModelState.IsValid) { try { string Username = form.Username; bool UsernameExists = _dataAccess.UsernameExists(Username); //The "!" is "not", "Username does not exist" if (!UsernameExists) { RegisterDO dataObject = RegisterMapper.RegisterPOToDO(form); _dataAccess.RegisterUser(dataObject); //has user login after they have registered response = RedirectToAction("Login", "Account"); } else { ModelState.AddModelError("Username", "Username already in use, please try a different username."); response = View(); } } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } } else { response = View(form); } return(response); }