Esempio n. 1
0
        public List <CatalogDataModel> GetModelFromFile()
        {
            List <CatalogDataModel> result = new List <CatalogDataModel>();

            string[] lines = File.ReadAllLines(Filename);
            for (int i = 0; i < lines.Length; i++)
            {
                string[] data = lines[i].Split(';');

                int    id     = int.Parse(data[0]);
                double length = double.Parse(data[5]);

                int year = int.Parse(data[3]);

                var model = new CatalogDataModel()
                {
                    Id       = id,
                    SongName = data[1],
                    Singer   = data[2],
                    Year     = year,
                    Genre    = data[4],
                    Length   = length,
                };
                result.Add(model);
            }
            return(result);
        }
Esempio n. 2
0
 public void WriteToDatabase(CatalogDataModel model)
 {
     using (var db = new Database())
     {
         db.Songs.Add(model);
         db.SaveChanges();
     }
 }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            var model = new CatalogDataModel()
            {
                SongName = textBox1.Text,
                Singer   = textBox2.Text,
                Year     = int.Parse(textBox3.Text),
                Genre    = textBox4.Text,
                Length   = double.Parse(textBox5.Text)
            };

            controller.WriteToDatabase(model);
            this.Close();
        }