public ActionResult Index(Models.selectSubstitute newSubstitute)
        {
            int    tempSubstituteID = 0;
            string userID           = " ";

            //to get the id of the person logged in as
            var claimsIdentity = User.Identity as System.Security.Claims.ClaimsIdentity;

            if (claimsIdentity != null)
            {
                var c = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
                if (c != null)
                {
                    userID = c.Value;
                }
            }

            //to get the id of the selected person
            var    connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            string queryString      = "Select Employee.Employee_ID From dbo.Employee Where Employee_Id='" + newSubstitute.substituteStaffID + "'";

            using (var connection = new SqlConnection(connectionString))
            {
                var command = new SqlCommand(queryString, connection);
                connection.Open();
                using (var reader = command.ExecuteReader())
                    while (reader.Read())
                    {
                        tempSubstituteID = (int)reader[0];
                    }
                connection.Close();
            }

            //to update current hr responsible as hr
            string insertString = "Update dbo.Employee_Role SET Role_ID ='3' Where Employee_ID='" + userID + "'";

            using (var connection = new SqlConnection(connectionString))
            {
                var command = new SqlCommand(insertString, connection);
                connection.Open();
                using (var reader = command.ExecuteReader())
                    connection.Close();
            }

            //to update the selected person as hr responsible
            insertString = "Update dbo.Employee_Role SET Role_ID ='2' Where Employee_ID='" + tempSubstituteID + "'";
            using (var connection = new SqlConnection(connectionString))
            {
                var command = new SqlCommand(insertString, connection);
                connection.Open();
                using (var reader = command.ExecuteReader())
                    connection.Close();
                Response.Write("<script> alert ('Successfully changed HR Responsible')</script>");
            }

            return(Index());
        }
Esempio n. 2
0
        public ActionResult Index(Models.selectSubstitute newSubstitute)
        {
            string userID = " ";

            //to get the id of the person logged in as
            var claimsIdentity = User.Identity as System.Security.Claims.ClaimsIdentity;

            if (claimsIdentity != null)
            {
                var c = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
                if (c != null)
                {
                    userID = c.Value;
                }
            }

            int tempSubstituteID = 0;

            if (newSubstitute.toTransferBack)
            {
                //to remove the substitute id from the database
                var    connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                string insertString     = "Update dbo.Department SET Substitute_LM_ID = NULL Where Line_Manager_ID= '" + userID + "'";
                using (var connection = new SqlConnection(connectionString))
                {
                    var command = new SqlCommand(insertString, connection);
                    connection.Open();
                    using (var reader = command.ExecuteReader())
                        connection.Close();
                }
                Response.Write("<script> alert ('Successfully Transfered Authority Back')</script>");
            }
            else

            {
                //get the name selected in the list to appoint as substitute
                var    connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                string queryString      = "Select Employee.Employee_ID From dbo.Employee Where Employee_Id='" + newSubstitute.substituteStaffID + "'";
                using (var connection = new SqlConnection(connectionString))
                {
                    var command = new SqlCommand(queryString, connection);
                    connection.Open();
                    using (var reader = command.ExecuteReader())
                        while (reader.Read())
                        {
                            tempSubstituteID = (int)reader[0];
                        }
                    connection.Close();
                    //System.Diagnostics.Debug.WriteLine("This the LM ID - " + tempSubstituteID);
                }

                //add the id of the substitute into the databse
                string insertString = "Update dbo.Department SET Substitute_LM_ID ='" + tempSubstituteID + "' Where Line_Manager_ID='" + userID + "'";
                using (var connection = new SqlConnection(connectionString))
                {
                    var command = new SqlCommand(insertString, connection);
                    connection.Open();
                    using (var reader = command.ExecuteReader())
                        connection.Close();
                }
                Response.Write("<script> alert ('Successfully added Substitute Line Manager')</script>");
            }
            return(Index());
        }