|
|
@ -2,6 +2,7 @@
|
|
|
|
using PersonalMVVMToolkit;
|
|
|
|
using PersonalMVVMToolkit;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Windows.Input;
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ViewModels
|
|
|
|
namespace ViewModels
|
|
|
@ -28,6 +29,8 @@ namespace ViewModels
|
|
|
|
private AuthorVM selectedAuthor;
|
|
|
|
private AuthorVM selectedAuthor;
|
|
|
|
private ContactVM selectedContact;
|
|
|
|
private ContactVM selectedContact;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string givenFirstName;
|
|
|
|
|
|
|
|
private string givenLastName;
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
#region Properties
|
|
|
@ -121,6 +124,32 @@ namespace ViewModels
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string GivenFirstName
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get { return givenFirstName; }
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (givenFirstName != value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
givenFirstName = value;
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(GivenFirstName));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string GivenLastName
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get { return givenLastName; }
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (givenLastName != value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
givenLastName = value;
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(GivenLastName));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string SearchTitle { get; private set; }
|
|
|
|
public string SearchTitle { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public int Index
|
|
|
|
public int Index
|
|
|
@ -222,7 +251,7 @@ namespace ViewModels
|
|
|
|
GetPastBorrowingsCommand = new RelayCommand(() => GetPastBorrowings());
|
|
|
|
GetPastBorrowingsCommand = new RelayCommand(() => GetPastBorrowings());
|
|
|
|
LendBookCommand = new RelayCommand<ContactVM>((contactVM) => LendBook(contactVM));
|
|
|
|
LendBookCommand = new RelayCommand<ContactVM>((contactVM) => LendBook(contactVM));
|
|
|
|
GetContactsCommand = new RelayCommand(() => GetContacts());
|
|
|
|
GetContactsCommand = new RelayCommand(() => GetContacts());
|
|
|
|
AddContactCommand = new RelayCommand<ContactVM>((contactVM) => AddContact(contactVM));
|
|
|
|
AddContactCommand = new RelayCommand(() => AddContact());
|
|
|
|
//GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book)));
|
|
|
|
//GetBooksByTitleCommand = new RelayCommand(() => AllBooks = model.GetBooksByTitle(SearchTitle, Index, Count).Result.books.Select(book => new BookVM(book)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -540,22 +569,33 @@ namespace ViewModels
|
|
|
|
OnPropertyChanged(nameof(AllContacts));
|
|
|
|
OnPropertyChanged(nameof(AllContacts));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task AddContact(ContactVM contactVM)
|
|
|
|
private async Task AddContact()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Model.Contact contact = new Model.Contact();
|
|
|
|
var result = await Model.GetContacts(Index, Count);
|
|
|
|
var resultContacts = await Model.GetContacts(Index, Count);
|
|
|
|
IEnumerable<Model.Contact> someContacts = result.contacts;
|
|
|
|
var allContacts = resultContacts.contacts;
|
|
|
|
|
|
|
|
foreach (var c in allContacts)
|
|
|
|
int lastSequence = someContacts
|
|
|
|
{
|
|
|
|
.Where(c => Regex.IsMatch(c.Id, @"^/contacts/\d+$"))
|
|
|
|
if (c.Id == contactVM.Id)
|
|
|
|
.Select(c => int.Parse(Regex.Match(c.Id, @"\d+").Value))
|
|
|
|
{
|
|
|
|
.DefaultIfEmpty(0)
|
|
|
|
contact = c;
|
|
|
|
.Max();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
int newSequence = lastSequence + 1;
|
|
|
|
if (contact != null)
|
|
|
|
|
|
|
|
|
|
|
|
string newId = $"/contacts/{newSequence:D2}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newContact = new Model.Contact
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await Model.AddContact(contact);
|
|
|
|
Id = newId,
|
|
|
|
}
|
|
|
|
FirstName = GivenFirstName,
|
|
|
|
|
|
|
|
LastName = GivenLastName
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GivenFirstName = null;
|
|
|
|
|
|
|
|
GivenLastName = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Model.AddContact(newContact);
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(AllContacts));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|