Beispiel #1
0
 public void AddWithStreamWriter(Cellphone phone)
 {
     //string text = "";
     //using (StreamReader sReader = new StreamReader(PathFileRepository))
     //{
     //    text = sReader.ReadToEnd();
     //}
     //using (StreamWriter sWriter = new StreamWriter(PathFileRepository))
     //{
     //    sWriter.WriteLine(text + JsonConvert.SerializeObject(phone));
     //}
     using (StreamWriter sWriter = new StreamWriter(PathFileRepository, true))
     {
         sWriter.WriteLine(JsonConvert.SerializeObject(phone));
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Example1
            //WorkWithFiles.FileSaveRead();

            // Example2

            var repository = new CellphonesRepository();
            var cellphone  = new Cellphone
            {
                Id           = 1,
                Manufacturer = "Apple",
                Model        = "X",
                Price        = 3402.50
            };
            var cellphone1 = new Cellphone
            {
                Id           = 2,
                Manufacturer = "Samsung",
                Model        = "Galaxy S7",
                Price        = 2087.33
            };
            var cellphone2 = new Cellphone
            {
                Id           = 3,
                Manufacturer = "Samsung",
                Model        = "Torsh 8X",
                Price        = 807.15
            };

            repository.Add(cellphone);
            //repository.Add(cellphone1);
            repository.AddWithStreamWriter(cellphone1);
            repository.Add(cellphone2);
            var phones = repository.GetAll();

            repository.Print(phones);

            repository.Remove(3);
            Console.WriteLine("======== after remove ========");

            phones = repository.GetAll();

            repository.Print(phones);

            Console.ReadKey();
        }
Beispiel #3
0
        public void Add(Cellphone phone)
        {
            var phoneString = JsonConvert.SerializeObject(phone);

            File.AppendAllLines(PathFileRepository, new[] { phoneString });
        }