public IHttpActionResult ViewVendorDetailsByPage(int max, int page, string sort_col, string sort_dir, string search = null) { Paged_ACRF_VendorDetailsModel objList = new Paged_ACRF_VendorDetailsModel(); try { objList = objVendorDetailsVM.ListVendorDetailsByPagination(max, page, search, sort_col, sort_dir); } catch (Exception ex) { ErrorHandlerClass.LogError(ex); } return(Ok(new { results = objList })); }
public Paged_ACRF_VendorDetailsModel ListVendorDetailsByPagination(int max, int page, string search, string sort_col, string sort_dir) { Paged_ACRF_VendorDetailsModel objPaged = new Paged_ACRF_VendorDetailsModel(); List <ACRF_VendorDetailsModel> objList = new List <ACRF_VendorDetailsModel>(); try { if (search == null) { search = ""; } int startIndex = max * (page - 1); string sqlstr = "[ACRF_GetProjectDetailsByPage]"; var connection = gConnection.Connection(); connection.Open(); SqlCommand cmd = new SqlCommand(sqlstr, connection); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@startRowIndex", startIndex); cmd.Parameters.AddWithValue("@pageSize", max); cmd.Parameters.AddWithValue("@search", search); cmd.Parameters.AddWithValue("@sort_col", sort_col); cmd.Parameters.AddWithValue("@sort_dir", sort_dir); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { ACRF_VendorDetailsModel tempobj = new ACRF_VendorDetailsModel(); tempobj.Id = Convert.ToInt32(sdr["Id"].ToString()); tempobj.ProjectName = sdr["ProjectName"].ToString(); //tempobj.Address = sdr["Address"].ToString(); tempobj.ManagerName = sdr["ManagerName"].ToString(); tempobj.Mobile = sdr["Mobile"].ToString(); tempobj.Email = sdr["Email"].ToString(); // tempobj.FAX = sdr["FAX"].ToString(); tempobj.SkypeId = sdr["SkypeId"].ToString(); //tempobj.Website = sdr["Website"].ToString(); //tempobj.MiscInfo = sdr["MiscInfo"].ToString(); //tempobj.CountryId = Convert.ToInt32(sdr["CountryId"].ToString()); //tempobj.PostalCode = sdr["PostalCode"].ToString(); tempobj.LastLogin = Convert.ToDateTime(sdr["LastLogin"].ToString()); tempobj.CreatedBy = sdr["CreatedBy"].ToString(); tempobj.CreatedOn = Convert.ToDateTime(sdr["CreatedOn"].ToString()); var usCulture = new System.Globalization.CultureInfo("en-US"); // tempobj.SprintStartDate= Convert.ToDateTime(sdr["SprintStartDate"].ToString()).ToShortDateString(); //tempobj.SprintEndDate = Convert.ToDateTime(sdr["SprintEndDate"].ToString()); tempobj.SprintStartDate = sdr["SprintStartDate"].ToString(); tempobj.SprintEndDate = sdr["SprintEndDate"].ToString(); tempobj.CurrentSprintName = sdr["CurrentSprintName"].ToString(); tempobj.Devhours = Convert.ToInt32(sdr["Devhours"].ToString()); tempobj.Testhours = Convert.ToInt32(sdr["Testhours"].ToString()); objList.Add(tempobj); } sdr.Close(); objPaged.ACRF_VendorDetailsModelList = objList; sqlstr = "select count(*) as cnt from ProjectDetails where ProjectName like @search "; cmd.Parameters.Clear(); cmd.CommandText = sqlstr; cmd.Connection = connection; cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@search", '%' + @search + '%'); sdr = cmd.ExecuteReader(); while (sdr.Read()) { objPaged.PageCount = Convert.ToInt32(sdr["cnt"].ToString()); } connection.Close(); } catch (Exception ex) { ErrorHandlerClass.LogError(ex); } return(objPaged); }