public async Task GetRaitings(CategoryEnum category) { if (initializedRait == true) { return; } IsBusy = true; IEnumerable <Raiting> raitings = await quizService.GetRaiting(); while (Raitings.Any()) { Raitings.RemoveAt(Quizzes.Count - 1); } // добавляем загруженные данные foreach (Raiting raiting in raitings) { if (raiting.Category == category) { Raitings.Add(raiting); } } List <Raiting> tmp = Raitings.ToList(); tmp.Sort((x, y) => x.Points.CompareTo(y.Points)); tmp.Reverse(); Raitings = new ObservableCollection <Raiting>(tmp); IsBusy = false; initializedRait = true; }
public async Task SaveRaiting(object raitingObj) { Raiting raiting = raitingObj as Raiting; if (raiting != null) { IsBusy = true; // редактирование if (raiting.Id > 0) { Raiting updateRaiting = await quizService.UpdateRaiting(raiting); // заменяем объект в списке на новый if (updateRaiting != null) { await GetAllRaitings(); int pos = raiting.Id - 1; Raitings.RemoveAt(pos); Raitings.Insert(pos, updateRaiting); } } // добавление else { Raiting addedRaiting = await quizService.AddRaiting(raiting); if (addedRaiting != null) { Raitings.Add(addedRaiting); } } IsBusy = false; } }