Exemple #1
0
        public List <Product> LoadFromTxt()
        {
            List <Product> results = new List <Product>();
            StreamReader   sr      = null;

            try
            {
                sr = new StreamReader(FILENAME);
                sr.ReadLine();
                string row = "";
                while ((row = sr.ReadLine()) != null)
                {
                    Product c = ProductMapper.StringToProduct(row);
                    results.Add(c);
                }
            }
            catch (FileNotFoundException fileNotFound)
            {
                Console.WriteLine(fileNotFound.FileName + " was not found");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
            return(results);
        }
Exemple #2
0
        public Product GetProductByName(string name)
        {
            var query = from p in ProductMapper.GetAllProducts()
                        where p.ProductType == name
                        select p;

            return(query.FirstOrDefault());
        }
Exemple #3
0
        public static List <Products> GetProducts()
        {
            List <Products> product = new List <Products>();

            try
            {
                using (StreamReader streamReader = new StreamReader("Product.txt"))
                {
                    string row = streamReader.ReadLine();
                    while ((row = streamReader.ReadLine()) != null)
                    {
                        Products products = ProductMapper.ToProduct(row);
                        product.Add(products);
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Not valid");
            }
            return(product);
        }
Exemple #4
0
 public IEnumerable <Product> GetAllProducts()
 {
     return(ProductMapper.GetAllProducts());
 }