예제 #1
0
        public async Task <IActionResult> AddEmployee(int id)
        {
            try
            {
                var model        = new List <AddUserDepartment>();
                var employeeUser = await _userManager.GetUsersInRoleAsync("Employee");

                foreach (var emp in employeeUser)
                {
                    var empModel = new AddUserDepartment()
                    {
                        DepId    = id,
                        UserId   = emp.Id,
                        FullName = emp.FirstName + " " + emp.FatherName + " " + emp.LastName
                    };
                    var userDepResult = await _userDepartmentService.GetUsersOfDepartmentAsync();

                    if (userDepResult.Succeeded)
                    {
                        var userDep = userDepResult.Model;
                        foreach (var item in userDep)
                        {
                            if (item.UserId == emp.Id && item.DepartmentId == id)
                            {
                                empModel.IsSelected = true;
                            }
                        }
                    }
                    model.Add(empModel);
                }

                return(View(model));
            }
            catch (Exception)
            {
                ViewBag.Error = "Something wrong";
                return(View("Error"));
            }
        }
예제 #2
0
        protected void AddUserSubmit_Click(object sender, EventArgs e)
        {
            string        uid = AddUserId.Text.ToString();
            string        CS  = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
            SqlConnection con = new SqlConnection(CS);
            SqlCommand    cmd = new SqlCommand();

            cmd.CommandText = "Select * from usertnp where id = @uid";
            cmd.Parameters.AddWithValue("@uid", uid);

            cmd.Connection = con;
            con.Open();

            DataSet ds = new DataSet();

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(ds);
            con.Close();

            bool loginSuccessful = ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0));

            if (loginSuccessful)
            {
                USerExistLabel.Text = "User you entered already exist";
            }
            else
            {
                if (AddUserType.SelectedIndex == 0)
                {
                    USerExistLabel.Text = "Please select a user type";
                    AddUserType.Focus();
                }
                else if (AddUserType.SelectedIndex == 2 && AddUserDepartment.SelectedIndex == 0)
                {
                    USerExistLabel.Text = "Please select a department of the coordinator";
                    AddUserDepartment.Focus();
                }
                else
                {
                    string     pswd      = AddUserPassword.Text.ToString();
                    string     email     = AddUserEmail.Text.ToString();
                    string     type      = AddUserType.SelectedValue.ToString();
                    SqlCommand insertcmd = new SqlCommand();
                    insertcmd.CommandText = "insert into usertnp values(@uid,@pswd,@type,@email,@uid)";
                    insertcmd.Parameters.AddWithValue("@uid", uid);
                    insertcmd.Parameters.AddWithValue("@pswd", pswd);
                    insertcmd.Parameters.AddWithValue("@type", type);
                    insertcmd.Parameters.AddWithValue("@email", email);

                    //Command for inserting in other tables
                    SqlCommand insertcmdforeign = new SqlCommand();
                    insertcmdforeign.CommandText = "insert into academic_details(aid) values(@uid)";
                    insertcmdforeign.Parameters.AddWithValue("@uid", uid);
                    insertcmdforeign.Parameters.AddWithValue("@codept", AddUserDepartment.SelectedValue.ToString());
                    insertcmdforeign.Connection = con;
                    insertcmd.Connection        = con;
                    con.Open();
                    insertcmd.ExecuteNonQuery();
                    //Execution of foreign
                    if (AddUserType.SelectedIndex == 1)
                    {
                        //Academic details insert through table
                        //insertcmdforeign.ExecuteNonQuery();
                        insertcmdforeign.CommandText = "insert into notification_details(notid) values(@uid)";
                        insertcmdforeign.ExecuteNonQuery();
                        insertcmdforeign.CommandText = "insert into document_details(docid) values(@uid)";
                        insertcmdforeign.ExecuteNonQuery();
                        //Personal details insert through table
                        // insertcmdforeign.CommandText = "insert into personal_details(pid) values(@uid)";
                        //insertcmdforeign.ExecuteNonQuery();
                        //insertcmdforeign.CommandText = "insert into student_details values(@uid,@uid,@uid,@uid,@uid,@uid,@uid)";
                        //insertcmdforeign.ExecuteNonQuery();
                    }
                    else if (AddUserType.SelectedIndex == 2)
                    {
                        insertcmdforeign.CommandText = "insert into coordinator values(@uid,'',@codept)";
                        insertcmdforeign.ExecuteNonQuery();
                    }
                    else
                    {
                        insertcmdforeign.CommandText = "insert into admin_details(id) values(@uid)";
                        insertcmdforeign.ExecuteNonQuery();
                    }

                    con.Close();
                    //Clear field after adding user
                    USerExistLabel.Text  = "";
                    UserAddedLabel.Text  = "User Added Successfully";
                    AddUserId.Text       = "";
                    AddUserEmail.Text    = "";
                    AddUserPassword.Text = "";
                    AddUserType.ClearSelection();
                }
            }
        }