private void buttonSerializeDiscs_Click(object sender, EventArgs e) { using (FileStream fs = new FileStream("discs.json", FileMode.OpenOrCreate)) { IDiscsRepository discsRep = new DiscsRepository(); List <DiscModel> discs = discsRep.GetAllDiscs().ToList(); var options = new JsonSerializerOptions { WriteIndented = true }; foreach (DiscModel disc in discs) { JsonSerializer.SerializeAsync(fs, disc, options); } } }
private void buttonSeeDiscs_Click(object sender, EventArgs e) { IDiscsRepository discsRep = new DiscsRepository(); List <DiscModel> discs = discsRep.GetAllDiscs().ToList(); listDiscs.Items.Clear(); foreach (DiscModel disc in discs) { string toList = "Disc title:" + disc.Title + ", disc serial number:" + disc.SerialNumber + ", date of release:" + disc.DateOfRelease + ", sold in current year:" + disc.SaledInCurrentYear + ", in last year:" + disc.SaledInLastYear + ", how much left:" + disc.HowMuchLeft + ", retail price:" + disc.RetailPrice + ", wholesale:" + disc.WholesalePrice + ", wholesale company:" + disc.WholesaleCompany + ", list of songs:" + disc.ListOfSongs; listDiscs.Items.Add(toList); } }