public static Person makePerson(string userId, string person_name, string token) { // Set Instance bankInstance = new TestBank(); friendManagerInstance = new TestFriendManager(); Person person = new Person(userId, person_name, token, bankInstance, friendManagerInstance); return person; }
// Go to debt private async Task borrow(Person me, Person friend, int amount) { MobileServiceCollection<Debt, Debt> debt = null; try { debt = await debtTable .Where(d => d.host_person_name == me.person_name && d.friend_person_name == friend.person_name) .ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { } if (debt.Count > 0) { debt.First().addDebt(amount); await debtTable.UpdateAsync(debt.First()); } else await debtTable.InsertAsync(new Debt(me.person_name, friend.person_name, amount)); }
// Check whether it exists in DB private async Task<bool> isAlreadyFriend(Person friend) { MobileServiceCollection<FriendRelation, FriendRelation> friendRelation = null; try { friendRelation = await friendRelationTable .Where(f => f.friend_person_live_id == friend.person_live_id) .ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { } if (friendRelation.Count > 0) return true; else return false; }
// Add Friend private async Task<bool> addFriend(Person me, string friendName) { bool result = false; MessageDialog dialog = null; string title = null; string message = null; Person friend = await isExistedPerson(friendName); if (friend == null) // No registered friend { title = "없는 회원"; message = "빚쟁이에 아직 등록되지 않은 회원입니다."; } else // registered friend { if (!me.person_live_id.Equals(friend.person_live_id)) { if ((await isAlreadyFriend(friend))) // He was already registed as my friend { title = "친구"; message = "우리는 이미 친구입니다."; } else // New friend { await friendRelationTable.InsertAsync(new FriendRelation(me.person_live_id, friend.person_live_id)); await friendRelationTable.InsertAsync(new FriendRelation(friend.person_live_id, me.person_live_id)); title = "친구 등록"; message = friendName + "님을 친구로 등록하였습니다."; result = true; } } else { title = "나 자신"; message = "자신은 친구로 등록하지 못합니다."; } } dialog = new MessageDialog(message, title); dialog.Commands.Add(new UICommand("확인")); await dialog.ShowAsync(); return result; }
// Get Friends List private async Task<List<Person>> getFriends(Person me) { // Get Relations MobileServiceCollection<FriendRelation, FriendRelation> friendRelations = null; try { friendRelations = await friendRelationTable .Where(f => f.host_person_live_id == me.person_live_id) .ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { } // Do job if he has friends List<Person> people = new List<Person>(); // Get Friends try { foreach (FriendRelation friendRelation in friendRelations) { MobileServiceCollection<Person, Person> friend = null; try { friend = await personTable .Where(p => p.person_live_id == friendRelation.friend_person_live_id) .ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { } people.Add(friend.First()); } } catch (MobileServiceInvalidOperationException e) { } return people; }
// Set List View private async Task setDebtListView(Person me) { List<Person> people = await getFriends(me); // Set friendListView.Items.Clear(); foreach (Person person in people) { FriendListViewItem friend = new FriendListViewItem(person); friendListView.Items.Add(friend); } }
/// 이 섹션에서 제공되는 메서드는 NavigationHelper에서 /// 페이지의 탐색 메서드에 응답하기 위해 사용됩니다. /// /// 페이지별 논리는 다음에 대한 이벤트 처리기에 있어야 합니다. /// <see cref="GridCS.Common.NavigationHelper.LoadState"/> /// 및 <see cref="GridCS.Common.NavigationHelper.SaveState"/>입니다. /// 탐색 매개 변수는 LoadState 메서드 /// 및 이전 세션 동안 유지된 페이지 상태에서 사용할 수 있습니다. protected async override void OnNavigatedTo(NavigationEventArgs e) { // Get parameter navigationHelper.OnNavigatedTo(e); me = e.Parameter as Person; // Set Listview await setDebtListView(me); }
public FriendListViewItem(Person person) { this.InitializeComponent(); this.person = person; nameText.Text = person.person_name; }
private async Task<MobileServiceCollection<Debt, Debt>> getDebts(Person me) { // Get Relations MobileServiceCollection<Debt, Debt> debts = null; try { debts = await debtTable .Where(d => d.host_person_name == me.person_name) .ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { } return debts; }
// Set DebtListView private async Task setDebtListView(Person me) { MobileServiceCollection<Debt, Debt> debts = await getDebts(me); int amount = 0; if (debts.Count > 0) { debtListView.Items.Clear(); foreach (Debt debt in debts) { if (debt.amount != 0) { amount += debt.amount; DebtListViewItem debtListViewItem = new DebtListViewItem(debt); debtListView.Items.Add(debtListViewItem); } } totalDebtText.Text = "" + amount; } }