Ejemplo n.º 1
0
        public ActionResult GetData()
        {
            List <RapidDataUsers> employee = new List <RapidDataUsers>();

            try
            {
                string        query      = "select * from  RapidDataUsers;";
                SqlConnection connection = new SqlConnection(constrs);
                SqlCommand    cmd        = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    RapidDataUsers newstud = new RapidDataUsers();
                    newstud.UserId            = Convert.ToInt32(sdr["UserId"]) == 0 ? 0 : Convert.ToInt32(sdr["UserId"]);
                    newstud.UserName          = (sdr["UserName"]) == DBNull.Value ? string.Empty : sdr["UserName"].ToString();
                    newstud.phoneNumber       = (sdr["phoneNumber"]) == DBNull.Value ? string.Empty : sdr["phoneNumber"].ToString();
                    newstud.RoleName          = (sdr["RoleName"]) == DBNull.Value ? string.Empty : sdr["RoleName"].ToString();
                    newstud.CreatedBy         = (sdr["CreatedBy"]) == DBNull.Value ? string.Empty : sdr["CreatedBy"].ToString();
                    newstud.CreadtedTimestamp = (sdr["CreadtedTimestamp"]) == DBNull.Value ? DateTime.Now : Convert.ToDateTime(sdr["CreadtedTimestamp"]);
                    newstud.Sessionrolename   = Session["RoleName"].ToString();
                    employee.Add(newstud);
                }
                sdr.Close();
                connection.Close();
                return(Json(new { data = employee }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(employee, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
        public ActionResult createEmployeorEdit(int id = 0)
        {
            if (id == 0)
            {
                using (SqlConnection sqlCon = new SqlConnection(constrs))
                {
                    string query1 = "select  RoleId, RoleName from Role";
                    List <SelectListItem> Rolelist = new List <SelectListItem>();
                    SqlCommand            cmd      = new SqlCommand(query1, sqlCon);
                    sqlCon.Open();
                    SqlDataReader sdr = cmd.ExecuteReader();
                    while (sdr.Read())
                    {
                        Rolelist.Add(new SelectListItem {
                            Text = sdr["RoleName"].ToString(), Value = sdr["RoleName"].ToString()
                        });
                    }

                    ViewBag.employerole = Rolelist;
                    sdr.Close();
                }
                return(View(new RapidDataUsers()));
            }

            else
            {
                using (SqlConnection sqlCon = new SqlConnection(constrs))
                {
                    string query1 = "select  RoleId, RoleName from Role";
                    List <SelectListItem> Rolelist = new List <SelectListItem>();
                    SqlCommand            cmd      = new SqlCommand(query1, sqlCon);
                    cmd.Parameters.AddWithValue("@UserId", id);
                    sqlCon.Open();
                    SqlDataReader sdr = cmd.ExecuteReader();
                    while (sdr.Read())
                    {
                        Rolelist.Add(new SelectListItem {
                            Text = sdr["RoleName"].ToString(), Value = sdr["RoleName"].ToString()
                        });
                    }
                    sdr.Close();
                    ViewBag.employerole = Rolelist;
                    List <RapidDataUsers> employee = new List <RapidDataUsers>();
                    query1 = "select * from  RapidDataUsers where UserId=@UserId;";
                    cmd    = new SqlCommand(query1, sqlCon);
                    cmd.Parameters.AddWithValue("@UserId", id);
                    sdr = cmd.ExecuteReader();
                    while (sdr.Read())
                    {
                        RapidDataUsers newstud = new RapidDataUsers();
                        newstud.UserId            = Convert.ToInt32(sdr["UserId"]) == 0 ? 0 : Convert.ToInt32(sdr["UserId"]);
                        newstud.UserName          = (sdr["UserName"]) == DBNull.Value ? string.Empty : sdr["UserName"].ToString();
                        newstud.phoneNumber       = (sdr["phoneNumber"]) == DBNull.Value ? string.Empty : sdr["phoneNumber"].ToString();
                        newstud.RoleName          = (sdr["RoleName"]) == DBNull.Value ? string.Empty : sdr["RoleName"].ToString();
                        newstud.CreatedBy         = (sdr["CreatedBy"]) == DBNull.Value ? string.Empty : sdr["CreatedBy"].ToString();
                        newstud.CreadtedTimestamp = (DateTime)sdr["CreadtedTimestamp"];
                        newstud.Password          = (sdr["Password"]) == DBNull.Value ? string.Empty : sdr["Password"].ToString();
                        newstud.Password          = DecryptString(newstud.Password);

                        employee.Add(newstud);
                        return(View(newstud));
                    }
                    sdr.Close();
                    return(View());
                }
            }
        }