Esempio n. 1
0
        public bool NewUserRegister(UserRegisterModel regUser)
        {
            bool registerApproved = false;

            try
            {
                ConnectionStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                conn = new SqlConnection(ConnectionStr);
                conn.Open();

                string insertDate = regUser.DateOfJoining.ToString("MM/dd/yyyy");

                cmd = new SqlCommand("SELECT UserRole FROM EmployeeDB WHERE EmployeeID = @userID", conn);
                cmd.Parameters.AddWithValue("userID", regUser.EmployeeID);

                string userRole = Convert.ToString(cmd.ExecuteScalar());

                if (userRole != null && !userRole.Contains("U"))
                {
                    userRole = userRole + "U";
                    cmd = new SqlCommand("INSERT INTO EmployeeDB (EmployeeID, EmployeeName, DoJ, Email, PhoneNo, Password, UserRole, Deductions) VALUES (@userID, @uname, @DoJ, @Email, @Phno, @pswd, @userRole, 0.0)", conn);
                    cmd.Parameters.AddWithValue("userID", regUser.EmployeeID);
                    cmd.Parameters.AddWithValue("uname", regUser.Name);
                    cmd.Parameters.AddWithValue("DoJ", insertDate);
                    cmd.Parameters.AddWithValue("Email", regUser.EmailId);
                    cmd.Parameters.AddWithValue("Phno", regUser.PhoneNumber);
                    cmd.Parameters.AddWithValue("pswd", regUser.Password);
                    cmd.Parameters.AddWithValue("userRole", userRole);

                    Debug.WriteLine("COMMAND: " + cmd.Parameters.ToString());

                    if (cmd.ExecuteNonQuery().Equals(1))
                    {
                        registerApproved = true;
                    }

                    else
                    {
                        registerApproved = false;
                    }
                }

                else
                {
                    registerApproved = false;
                }

                conn.Close();
            }

            catch (Exception)
            {
                registerApproved = false;
            }

            return registerApproved;
        }
        public string Register(string UserId, string UserName, string JoiningDate, string Password, string EmailId, string PhoneNumber)
        {
            UserAccountDAL agent = new UserAccountDAL();
            UserRegisterModel regUser = new UserRegisterModel();

            regUser.EmployeeID = UserId;
            regUser.Name = UserName;
            regUser.DateOfJoining = Convert.ToDateTime(JoiningDate);
            regUser.PhoneNumber = PhoneNumber;
            regUser.EmailId = EmailId;
            regUser.Password = PasswordGenerator.EncryptPassword(Password);

            try
            {
                bool res = agent.NewUserRegister(regUser);
                if (res)
                {
                    FormsAuthentication.SetAuthCookie(regUser.EmployeeID, false);
                    Session["UserID"] = regUser.EmployeeID;
                    Session["UserRole"] = "U";
                    return "DONE";
                }

                else
                {
                    //ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    //return View(regUser);
                    return "ERROR: Registration incorrect";
                }

            }
            catch
            {
                return "ERROR: Registration incorrect";
            }
        }