private static RegisterModel FillDataRecord(IDataReader dr) { var rm = new RegisterModel(); rm.Emp_ID = Int32.Parse(dr.GetString(dr.GetOrdinal("Emp_ID"))); rm.Emp_Name = dr.GetString(dr.GetOrdinal("Emp_Name")); rm.User_ID = dr.GetString(dr.GetOrdinal("User_ID")); rm.Gender = dr.GetString(dr.GetOrdinal("Gender")); rm.Job_Level = dr.GetInt32(dr.GetOrdinal("Job_Level")); rm.Job_Location = dr.GetString(dr.GetOrdinal("Job_Location")); rm.Access_Status = StatusDetail.AccessStatus(dr.GetString(dr.GetOrdinal("Access_Status"))); return rm; }
public static bool RegisterUserDAL(RegisterModel userData) { SqlDatabase travelMSysDB = new SqlDatabase(ConnString.DBConnectionString); SqlCommand insertCmmnd = new SqlCommand("INSERT INTO EMPLOYEES ([User_ID],[Password],[Emp_ID],[Emp_Name],[Gender],[Date_of_Birth],[Date_of_Joining],[Job_Level],[Job_Location]) VALUES (@User_ID,@Password,@Emp_ID,@Emp_Name,@Gender,@Date_of_Birth,@Date_of_Joining,@Job_Level,@Job_Location)"); insertCmmnd.CommandType = CommandType.Text; insertCmmnd.Parameters.AddWithValue("@User_ID", userData.User_ID); insertCmmnd.Parameters.AddWithValue("@Password", userData.Password); //insertCmmnd.Parameters.AddWithValue("@Access_Status",userData.Access_Status); insertCmmnd.Parameters.AddWithValue("@Emp_ID", userData.Emp_ID); insertCmmnd.Parameters.AddWithValue("@Emp_Name", userData.Emp_Name); insertCmmnd.Parameters.AddWithValue("@Gender", userData.Gender); insertCmmnd.Parameters.AddWithValue("@Date_of_Birth", userData.Date_of_Birth); insertCmmnd.Parameters.AddWithValue("@Date_of_Joining", userData.Date_of_Joining); insertCmmnd.Parameters.AddWithValue("@Job_Level", userData.Job_Level); insertCmmnd.Parameters.AddWithValue("@Job_Location", userData.Job_Location); int rowsAffected = travelMSysDB.ExecuteNonQuery(insertCmmnd); Console.Write("rowsAffected " + rowsAffected); if (rowsAffected == 1) return true; return false; }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { if (!RegisterBizLayer.RegisterUserBiz(model)) return View("Error"); string role = "Emp"; WebSecurity.CreateUserAndAccount(model.User_ID, model.Password); if (!Roles.RoleExists(role)) Roles.CreateRole(role); Roles.AddUserToRole(model.User_ID, role); WebSecurity.Login(model.User_ID, model.Password); ViewBag.Message = "Registration Successful! <a href=\"/Employee\">Go to Home page</a>"; return View("Success"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }