Example #1
0
        public ListProductResponse LoadProducts(string filePath)
        {
            ListProductResponse response = new ListProductResponse();

            response.Success     = true;
            response.ProductList = new List <Product>();

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    reader.ReadLine();
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        Product product = new Product();

                        string[] columns = line.Split(',');

                        product.FloorType              = columns[0];
                        product.CostPerSquareFoot      = decimal.Parse(columns[1]);
                        product.LaborCostPerSquareFoot = decimal.Parse(columns[2]);

                        response.ProductList.Add(product);
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
        public ListProductResponse LoadProducts(string filePath)
        {
            ListProductResponse response = new ListProductResponse();

            response.Success     = true;
            response.ProductList = _products;

            return(response);
        }
        public async Task <IActionResult> GetListProductPromotion([FromRoute] int id)
        {
            try
            {
                var listProductPromotion = await _context.ListProductPromotion.SingleOrDefaultAsync(m => m.Id == id);

                var response = new ListProductResponse
                {
                    SubPromotionDropDowns = iCodeProService.SubPromotionDropDowns(),
                    GoodCodeDropDowns     = iGetTranInvService.GoodCodeDropDowns(),
                    GoodCode = listProductPromotion
                };
                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Example #4
0
        public async Task <ActionResult <ListProductResponse> > Get([FromQuery] ProductParamRequest param = null)
        {
            try
            {
                var pageIndex = param?.Page ?? 0;
                var limit     = param?.Limit > 0 ? param.Limit : 100;
                var prods     = await ProductRepo.GetAllProducts(param.Sku, param.Name, param.PriceFrom, param.PriceTo, param.Description, pageIndex *limit, limit);

                var data = prods.Data.Select(x => new ProductDto
                {
                    Id          = x.Id,
                    Sku         = x.Sku,
                    Name        = x.Name,
                    Price       = x.Price,
                    Description = x.Description,
                    CreatedDate = x.CreatedDate,
                    UpdatedDate = x.ModifiedDate
                });
                var res = new ListProductResponse
                {
                    Data   = data.ToList(),
                    Paging = new Paging
                    {
                        Page      = pageIndex,
                        Limit     = limit,
                        TotalItem = prods.Total,
                        TotalPage = prods.Total / limit + 1
                    }
                };
                return(Ok(res));
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
                throw ex;
            }
        }
Example #5
0
        public ListProductResponse GetProductsList()
        {
            ListProductResponse response = _productRepository.LoadProducts(ConfigurationManager.AppSettings["ProductFilePath"].ToString());

            return(response);
        }