示例#1
0
        public List <District> GetAllDistrict(DistrictAdvanceSearch districtAdvanceSearch)
        {
            List <District> districtList = null;

            try
            {
                using (SqlConnection con = _databaseFactory.GetDBConnection())
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        if (con.State == ConnectionState.Closed)
                        {
                            con.Open();
                        }
                        cmd.Connection  = con;
                        cmd.CommandText = "[PSA].[GetAllDistrict]";
                        cmd.Parameters.Add("@SearchValue", SqlDbType.NVarChar, -1).Value = string.IsNullOrEmpty(districtAdvanceSearch.SearchTerm) ? "" : districtAdvanceSearch.SearchTerm;
                        cmd.Parameters.Add("@RowStart", SqlDbType.Int).Value             = districtAdvanceSearch.DataTablePaging.Start;
                        if (districtAdvanceSearch.DataTablePaging.Length == -1)
                        {
                            cmd.Parameters.AddWithValue("@Length", DBNull.Value);
                        }
                        else
                        {
                            cmd.Parameters.Add("@Length", SqlDbType.Int).Value = districtAdvanceSearch.DataTablePaging.Length;
                        }
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataReader sdr = cmd.ExecuteReader())
                        {
                            if ((sdr != null) && (sdr.HasRows))
                            {
                                districtList = new List <District>();
                                while (sdr.Read())
                                {
                                    District district = new District();
                                    {
                                        district.Code                           = (sdr["Code"].ToString() != "" ? int.Parse(sdr["Code"].ToString()) : district.Code);
                                        district.Country                        = new Country();
                                        district.Country.Description            = (sdr["Country"].ToString() != "" ? (sdr["Country"].ToString()) : district.Country.Description);
                                        district.State                          = new State();
                                        district.State.Description              = (sdr["State"].ToString() != "" ? (sdr["State"].ToString()) : district.State.Description);
                                        district.Description                    = (sdr["Description"].ToString() != "" ? sdr["Description"].ToString() : district.Description);
                                        district.PSASysCommon                   = new PSASysCommon();
                                        district.PSASysCommon.CreatedDateString = (sdr["CreatedDate"].ToString() != "" ? DateTime.Parse(sdr["CreatedDate"].ToString()).ToString(settings.DateFormat) : district.PSASysCommon.CreatedDateString);
                                        district.TotalCount                     = (sdr["TotalCount"].ToString() != "" ? int.Parse(sdr["TotalCount"].ToString()) : district.TotalCount);
                                        district.FilteredCount                  = (sdr["FilteredCount"].ToString() != "" ? int.Parse(sdr["FilteredCount"].ToString()) : district.FilteredCount);
                                    }
                                    districtList.Add(district);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(districtList);
        }
示例#2
0
 public List <District> GetAllDistrict(DistrictAdvanceSearch districtAdvanceSearch)
 {
     return(_districtRepository.GetAllDistrict(districtAdvanceSearch));
 }