public async override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state) { currentPerson = parameter == null ? new Person() { Id = Guid.NewGuid().ToString() } : parameter as Person; var temp = new PersonProxy(currentPerson) { Name = currentPerson.Name, LastName = currentPerson.LastName, Validator = i => { var u = i as PersonProxy; if (string.IsNullOrEmpty(u.Name)) { u.Properties[nameof(u.Name)].Errors.Add("First name is required"); } else if (u.Name.Length < 3) { u.Properties[nameof(u.Name)].Errors.Add("First name is less then 3 symbols"); } if (string.IsNullOrEmpty(u.LastName)) { u.Properties[nameof(u.LastName)].Errors.Add("Last name is required"); } if (string.IsNullOrEmpty(u.Email)) { u.Properties[nameof(u.Email)].Errors.Add("Email is required."); } else if (!new System.ComponentModel.DataAnnotations.EmailAddressAttribute().IsValid(u.Email)) { u.Properties[nameof(u.Email)].Errors.Add("A valid Email is required."); } }, }; TempPerson = temp; TempPerson.Validate(); if (parameter == null) { currentState = States.Add; Title = "Adding new person"; } else if (parameter != null) { currentState = States.Edit; Title = $"Editting {TempPerson.FullName}"; } await Task.CompletedTask; }
private void SetTempPerson(object person) { currentPerson = person == null ? new Person() { Id = Guid.NewGuid().ToString() } : person as Person; var temp = new PersonProxy(currentPerson) { Name = currentPerson.Name, LastName = currentPerson.LastName, Email = currentPerson.Email, DateOfBirth = currentPerson.DateOfBirth, Validator = i => { var u = i as PersonProxy; if (string.IsNullOrEmpty(u.Name)) { u.Properties[nameof(u.Name)].Errors.Add("FirstName is required"); } else if (u.Name.Length < 3) { u.Properties[nameof(u.Name)].Errors.Add("FirstName must be more then 3 symbols"); } if (string.IsNullOrEmpty(u.LastName)) { u.Properties[nameof(u.LastName)].Errors.Add("FirstName is required"); } if (string.IsNullOrEmpty(u.Email)) { u.Properties[nameof(u.Email)].Errors.Add("Email is required"); } else if (!new System.ComponentModel.DataAnnotations.EmailAddressAttribute().IsValid(u.Email)) { u.Properties[nameof(u.Email)].Errors.Add("Must consist . and @"); } } }; TempPerson = temp; TempPerson.Validate(); }
public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state) { if (parameter == null) { if (CachedAddingPerson != null) { //Если последняя операций была Edit, то нужно вернуть пёрсона из операций Add //Иначе продолжить создавать нового пёрсона if (CurrentState == States.Edit) { Title = "Adding new person"; CurrentState = States.Add; TempPerson = CachedAddingPerson; } return(Task.CompletedTask); } } else { if (CachedEditingPerson != null) { //Если ID кэшировнного редактируемого пёрсона совпадает с ID входящим пёрсоном //то значит редактируемый пёрсон в кэше и входящий одни и тот же пёрсон if (CahcedID == (parameter as Person).Id) { //Если последняя операций была Add, то нужно вернуть пёрсона из операций Edit //Иначе продолжить редактировать пёрсона if (CurrentState == States.Add) { CurrentState = States.Edit; TempPerson = CachedEditingPerson; Title = $"Editing {TempPerson.FullName}"; } return(Task.CompletedTask); } //Иначе это разные пёрсоны то тогда удалить хранящийся ID else { CahcedID = null; } } } currentPerson = parameter == null ? new Person() { Id = Guid.NewGuid().ToString() } : parameter as Person; var temp = new PersonProxy(currentPerson) { Name = currentPerson.Name, LastName = currentPerson.LastName, Email = currentPerson.Email, DateOfBirth = currentPerson.DateOfBirth, Validator = i => { var u = i as PersonProxy; if (string.IsNullOrEmpty(u.Name)) { u.Properties[nameof(u.Name)].Errors.Add("FirstName is required"); } else if (u.Name.Length < 3) { u.Properties[nameof(u.Name)].Errors.Add("FirstName must be more then 3 symbols"); } if (string.IsNullOrEmpty(u.LastName)) { u.Properties[nameof(u.LastName)].Errors.Add("FirstName is required"); } if (string.IsNullOrEmpty(u.Email)) { u.Properties[nameof(u.Email)].Errors.Add("Email is required"); } else if (!new System.ComponentModel.DataAnnotations.EmailAddressAttribute().IsValid(u.Email)) { u.Properties[nameof(u.Email)].Errors.Add("Must consist . and @"); } } }; TempPerson = temp; TempPerson.Validate(); if (parameter == null) { CurrentState = States.Add; Title = "Adding new person"; } else { CurrentState = States.Edit; Title = $"Editing {TempPerson.FullName}"; } return(Task.CompletedTask); }