/// <summary> /// Returns a list of region dimensions /// </summary> /// <param name="Page"></param> /// <param name="PageSize"></param> /// <returns></returns> public RegionListDTO GetRegionDimensions(int Page, int PageSize, string Region = "") { try { RegionListDTO list = DimensionDAL.GetRegionDimensions(Page, PageSize, Region); return(list); } catch (Exception) { throw; } }
/// <summary> /// Returns a list of regions from the database /// </summary> /// <returns></returns> public RegionListDTO GetRegionDimensions(int Page, int PageSize, string Region = "") { RegionListDTO list = new RegionListDTO(); SQLAzure.DbConnection dbConn = new SQLAzure.DbConnection(_connectionString); try { dbConn.Open(); SQLAzure.RetryLogic.DbCommand dbComm = new SQLAzure.RetryLogic.DbCommand(dbConn); if (Region != string.Empty) { dbComm.CommandText = String.Format("SELECT ID, Region, TotalCount = COUNT(ID) OVER() FROM DimRegion WHERE Region LIKE '%' + @Region + '%' ORDER BY ID OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY", (Page * PageSize), PageSize); dbComm.Parameters.Add(new SqlParameter("Region", Region)); } else { dbComm.CommandText = String.Format("SELECT ID, Region, TotalCount = COUNT(ID) OVER() FROM DimRegion ORDER BY ID OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY", (Page * PageSize), PageSize); } System.Data.IDataReader rdr = dbComm.ExecuteReader(System.Data.CommandType.Text); while (rdr.Read()) { RegionDTO region = new RegionDTO(); region.ID = Convert.ToInt32(rdr["ID"]); region.Region = rdr["Region"].ToString(); list.Items.Add(region); list.RecordCount = Convert.ToInt32(rdr["TotalCount"]); } list.PageNumber = Page; list.PageSize = PageSize; list.TotalPages = GetNumberOfPagesAvailable(PageSize, list.RecordCount); } catch (SqlException) { throw; } finally { dbConn.Close(); } return(list); }
public IHttpActionResult GetRegions() { IQueryable <region> regions = db.regions; List <RegionDTO> regionDTOs = new List <RegionDTO>(); foreach (region r in regions) { regionDTOs.Add(AutoMapper.Mapper.Map <RegionDTO>(r)); } RegionListDTO regionList = new RegionListDTO(); regionList.RegionList.AddRange(regionDTOs); return(Ok(regionList)); }
public IHttpActionResult Get(int Page, int PageSize, string Region = "") { ValidateModel(); try { RegionListDTO list = _dimensionBLL.GetRegionDimensions(Page, PageSize, Region); RegionDimensionList regionDimensions = new RegionDimensionList(); foreach (RegionDTO c in list.Items) { regionDimensions.Items.Add((RegionDimension)c); } if (regionDimensions.Items.Count > 0) { regionDimensions.PageNumber = list.PageNumber; regionDimensions.PageSize = list.PageSize; regionDimensions.RecordCount = list.RecordCount; regionDimensions.TotalPages = list.TotalPages; return(Ok(regionDimensions)); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NoContent); response.Content = new StringContent("No Content"); return(ResponseMessage(response)); } } catch (Exception ex) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.InternalServerError); response.Content = new StringContent("Unknown Error"); // Insert Logging here Console.WriteLine(ex); return(ResponseMessage(response)); } }