コード例 #1
0
        public List<MapResViewModel> GetMapResponseViewModels(MapReqViewModel mapReqViewModel)
        {
            List<string> districts = _productRepository.GetAllProduct().Select(e => e.District).Distinct().ToList();
            List<MapResViewModel> mapResViewModels = new List<MapResViewModel>();
            foreach (var district in districts)
            {
                var mapResViewModel = new MapResViewModel();
                mapResViewModel.District = district;

                IEnumerable<Product> prod = _productRepository.GetAllProduct().Where(p => p.District.Equals(district) && p.Name.Equals(mapReqViewModel.Name));
                if(prod.Count()<=0)
                    continue;
                
                mapResViewModel.AveragePrice = prod.Select(p => p.PriceRangeFrom + p.PriceRangeTo).Average() / 2.0;
                mapResViewModels.Add(mapResViewModel);
            }

            return mapResViewModels;
        }
コード例 #2
0
        public IHttpActionResult GetMapResponseViewModels(MapReqViewModel mapReqViewModel)
        {
            try
            {

                if (mapReqViewModel.Equals(null))
                    return BadRequest("null object");
                return Ok(_productService.GetMapResponseViewModels(mapReqViewModel));
            }
            catch (Exception)
            {
                return BadRequest("error");
            }
        }