Exemplo n.º 1
0
        public static void SaveData(BarDataModel barData)
        {
            var barsInFile = BarFileReader.GetAllBarData();

            foreach (var bar in barData)
            {
                var barInListIndex = barsInFile.FindIndex(x => x.Title == bar.Title);
                if (barInListIndex != -1)
                {
                    var barOccurenceInFile = barsInFile[barInListIndex];
                    if (barOccurenceInFile.Ratings == null ||
                        barsInFile[barInListIndex].Ratings.SequenceEqual(bar.Ratings))
                    {
                        barsInFile[barInListIndex].Ratings = bar.Ratings;
                    }
                }
                else
                {
                    barsInFile.Add(bar);
                }
            }
            var barsDataJson = JsonConvert.SerializeObject(barData);

            File.WriteAllText(_filePath, barsDataJson);
        }
Exemplo n.º 2
0
        public void AddRating(BarData barData, int rating)
        {
            var allBars = BarFileReader.GetAllBarData();

            if (barData.Ratings == null)
            {
                barData.Ratings = new List <int>();
            }
            barData.Ratings.Add(rating);
            // Update local copy of list
            BarsData.Find(x => x == barData).Ratings = barData.Ratings;

            var foundBar = allBars.FindIndex(x => x.Title == barData.Title);

            if (foundBar != -1)
            {
                allBars[foundBar].Ratings = barData.Ratings;
            }
            else
            {
                allBars.Add(barData);
            }

            BarFileWriter.SaveData(allBars);
        }