コード例 #1
0
 public JsonResult Detail()
 {
     var userdetaillist = new List<UserDetail>();
     using (var sqlcon = new SqlConnection(con))
     {
         sqlcon.Open();
         using (var sqlcmd = sqlcon.CreateCommand())
         {
             sqlcmd.CommandText = "dbo.usp_getuserdetails";
             sqlcmd.CommandType = CommandType.StoredProcedure;
             using (SqlDataReader dr=sqlcmd.ExecuteReader())
             {
                 if(dr.HasRows)
                 {
                     int userIdKOrdinal = dr.GetOrdinal("Userid");
                     int firstnameordinal = dr.GetOrdinal("firstname");
                     int lastnameordinal = dr.GetOrdinal("lastname");
                     int birthnameordinal = dr.GetOrdinal("birthdate");
                     while (dr.Read())
                     {
                         userdetail = new UserDetail
                         {
                             UserId=dr.GetInt32(userIdKOrdinal),
                             FirstName=dr.GetString(firstnameordinal),
                             LastName=dr.GetString(lastnameordinal),
                             Bdate=dr.GetInt32(birthnameordinal)
                         };
                         userdetaillist.Add(userdetail);
                     }
                 }
             }
         }
     }
     return Json(userdetaillist.ToList(),JsonRequestBehavior.AllowGet);
 }
コード例 #2
0
 public JsonResult Delete(UserDetail id)
 {
     using (var sqlcon = new SqlConnection(con))
     {
         sqlcon.Open();
         using (var sqlcmd = sqlcon.CreateCommand())
         {
             sqlcmd.CommandText = "usp_userdelete";
             sqlcmd.CommandType = CommandType.StoredProcedure;
             sqlcmd.Parameters.Add(new SqlParameter("@Userid", id.UserId));
             sqlcmd.ExecuteNonQuery();
         }
     }
     return Json(id, JsonRequestBehavior.AllowGet);
 }
コード例 #3
0
        public JsonResult SampleGrid(int rows, int page)
        {
            var userdetaillist = new List<UserDetail>();
            using (var sqlcon = new SqlConnection(con))
            {
                sqlcon.Open();
                using (var sqlcmd = sqlcon.CreateCommand())
                {
                    sqlcmd.CommandText = "dbo.usp_getuserdetails";
                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    using (SqlDataReader dr = sqlcmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            int userIdKOrdinal = dr.GetOrdinal("Userid");
                            int firstnameordinal = dr.GetOrdinal("firstname");
                            int lastnameordinal = dr.GetOrdinal("lastname");
                            int birthnameordinal = dr.GetOrdinal("birthdate");
                            while (dr.Read())
                            {
                                userdetail = new UserDetail
                                {
                                    UserId = dr.GetInt32(userIdKOrdinal),
                                    FirstName = dr.GetString(firstnameordinal),
                                    LastName = dr.GetString(lastnameordinal),
                                    Bdate = dr.GetInt32(birthnameordinal)
                                };
                                userdetaillist.Add(userdetail);
                            }
                        }
                    }
                    UserDetail gridDataResult = new UserDetail();
                    gridDataResult.TotalRowCount = userdetaillist.Count;

                    int totalPages = 2;
                    if (rows > 0)
                    {
                        totalPages = gridDataResult.TotalRowCount / rows;
                        if (gridDataResult.TotalRowCount % rows != 0)
                            totalPages += 1;
                    }

                    gridDataResult.TotalPageCount = totalPages;
                    //gridDataResult.GridData = people.Skip((page - 1) * rows).Take(rows);
                }
            }
            return Json(userdetaillist.ToList(),JsonRequestBehavior.AllowGet);
        }
コード例 #4
0
        public JsonResult Update(UserDetail item)
        {
            using (var sqlcon = new SqlConnection(con))
                {
                    sqlcon.Open();
                    using (var sqlcmd = sqlcon.CreateCommand())
                    {
                        sqlcmd.CommandText = "[dbo].[usp_student_update]";
                        sqlcmd.CommandType = CommandType.StoredProcedure;
                        sqlcmd.Parameters.Add(new SqlParameter("@userid", item.UserId));
                        sqlcmd.Parameters.Add(new SqlParameter("@FirstName", item.FirstName));
                        sqlcmd.Parameters.Add(new SqlParameter("@LastName", item.LastName));
                        sqlcmd.Parameters.Add(new SqlParameter("@birthdate", item.Bdate));
                        sqlcmd.ExecuteNonQuery();
                    }
                }

            return Json(item, JsonRequestBehavior.AllowGet);
        }
コード例 #5
0
 public ActionResult Index(UserDetail ud)
 {
     return View();
 }