public async void Initialize() { this.AuthorizedEmployee = SessionService.Instance.AuthorizedEmployee; Favorite favorite = new Favorite(); this.Favorites = await favorite.GetFavoritesAsync(); this.Date = new Card(); this.Date.Date = this.Date.Date.Date; this.Favorite = new Favorite(); Card card = new Card(); this.AllCards = await card.GetCardsAsync(); this.AllCards = AllCards.OrderBy(ac => ac.Date).ToList(); var FavoriteCheckCards = new List <Card>(); for (var i = 0; i < AllCards.Count; i++) { card = AllCards.ElementAt(i); //card.Id == Favorites.CardId && this.AuthorizedEmployee.Id == Favorites.EmployeeId if (Favorites.Any(f => f.CardId == card.Id && f.EmployeeId == this.AuthorizedEmployee.Id)) { //List<int> intList = new List<int>; card = AllCards.ElementAt(i); card.Favorite = true; FavoriteCheckCards.Add(card); //this.AllCards.RemoveAt(i); //this.Cards.Insert(i, card); //this.Cards.Insert(i, new Card() { Id = card.Id, CD = card.CD, Text = card.Text, Date = card.Date, FromId = card.FromId, ToId = card.ToId, Title = card.Title, Reply = card.Reply, Favorite = card.Favorite, PickUp = card.PickUp }); //this.Cards.Add(card); //this.AllCards.Insert(i, new Card() { Id = card.Id, CD = card.CD, Text = card.Text, Date = card.Date, FromId = card.FromId, ToId = card.ToId, Title = card.Title, Reply = card.Reply, Favorite = card.Favorite, PickUp = card.PickUp }); //this.Cards.Add(new Card() { Id = card.Id, CD = card.CD, Text = card.Text, Date = card.Date, FromId = card.FromId, ToId = card.ToId, Title=card.Title, Reply=card.Reply, Favorite=card.Favorite, PickUp=card.PickUp}); } else { FavoriteCheckCards.Add(card); } } this.Cards = FavoriteCheckCards; this.Cards = Cards.OrderBy(ac => ac.Date).ToList(); //this.AuthorizedEmployee = SessionService.Instance.AuthorizedEmployee; }
public async void Initialize() { Employee employees = new Employee(); Department departments = new Department(); Card card = new Card(); Favorite favorite = new Favorite(); //下のやつは、ログイン者のEmployee情報をAuthorizedEMployeeに入れてます。 this.AuthorizedEmployee = SessionService.Instance.AuthorizedEmployee; if (SessionService.Instance.AuthorizedEmployee != null) { this.Employees = await employees.GetEmployeesAsync(); this.Departments = await departments.GetDepartmentsAsync(); this.AllCards = await card.GetCardsAsync(); this.Favorites = await favorite.GetFavoritesAsync(); } #region FavoriteCards this.FavoriteCards = Favorites.Where(f => f.EmployeeId == this.AuthorizedEmployee.Id).ToList(); for (var i = 0; i < FavoriteCards.Count; i++) { favorite = FavoriteCards.ElementAt(i); favorite.Card.Favorite = true; FavoriteCards.RemoveAt(i); FavoriteCards.Insert(i, favorite); } #endregion #region SendCards this.SendCards = AllCards.Where(al => al.From.Id == this.AuthorizedEmployee.Id).ToList(); for (var i = 0; i < SendCards.Count; i++) { if (Favorites.Any(f => f.CardId == card.Id && f.EmployeeId == this.AuthorizedEmployee.Id)) { card = SendCards.ElementAt(i); card.Favorite = true; SendCards.RemoveAt(i); SendCards.Insert(i, card); } } #endregion #region ReceiveCards this.ReceiveCards = AllCards.Where(al => al.To.Id == this.AuthorizedEmployee.Id).ToList(); for (var i = 0; i < ReceiveCards.Count; i++) { if (Favorites.Any(f => f.CardId == card.Id && f.EmployeeId == this.AuthorizedEmployee.Id)) { card = ReceiveCards.ElementAt(i); card.Favorite = true; ReceiveCards.RemoveAt(i); ReceiveCards.Insert(i, card); } } #endregion var FavoriteCheckCards = new List <Card>(); for (var i = 0; i < AllCards.Count; i++) { card = AllCards.ElementAt(i); if (Favorites.Any(f => f.CardId == card.Id && f.EmployeeId == this.AuthorizedEmployee.Id)) { card = AllCards.ElementAt(i); card.Favorite = true; FavoriteCheckCards.Add(card); } } this.Cards = FavoriteCheckCards; this.Cards = Cards.OrderBy(ac => ac.Date).ToList(); }