private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var song = new Song { name = Name.Text, description = Description.Text, singer = Singer.Text, author = Author.Text, thumbnail = Thumbnail.Text, link = Link.Text, }; Dictionary <String, String> errors = song.Validate(); if (errors.Count == 0) { songService.CreateSong(song, fileService.ReadFromTxtFile()); validateService.ValidateTrue(); this.NavigationCacheMode = NavigationCacheMode.Disabled; this.Frame.Navigate(typeof(SongListOfMine)); } else { validateService.ValidateFalse(NameMessage, errors, "name"); validateService.ValidateFalse(SingerMessage, errors, "single"); validateService.ValidateFalse(ThumbnailMessage, errors, "thumbnail"); validateService.ValidateFalse(LinkMessage, errors, "link"); validateService.ValidateFalse(AuthorMessage, errors, "author"); } }
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var member = new LoginMember { email = Email.Text, password = Password.Password, }; Dictionary <string, string> errors = member.Validate(); if (errors.Count == 0) { try { var jsonResult = memberService.Login(member); if (jsonResult.Contains("error")) { throw new Exception("Invalid email or password!"); } var resMember = JsonConvert.DeserializeObject <LoginMember>(jsonResult); var token = resMember.token; var sampleFile = fileService.WriteIntoTxtFile(token); var pathOfSampleFile = sampleFile.Path; validateService.ValidateTrue(); this.NavigationCacheMode = NavigationCacheMode.Disabled; this.Frame.Navigate(typeof(NavigationView)); } catch (Exception exception) { MessageDialog dialog = new MessageDialog(exception.Message); await dialog.ShowAsync(); } } else { validateService.ValidateFalse(EmailMessage, errors, "email"); validateService.ValidateFalse(PasswordMessage, errors, "password"); } }
private async void ButtonBase_RegisterClick(object sender, RoutedEventArgs e) { var user = new User { firstName = FirstName.Text, lastName = LastName.Text, avatar = AvatarUrl.Text, phone = Phone.Text, address = Address.Text, introduction = Introduction.Text, gender = gender, birthday = Birthday.Date.ToString("yyyy-MM-dd"), email = Email.Text, password = Password.Password }; Dictionary <String, String> errors = user.Validate(); if (errors.Count == 0) { try { memberService.Register(user); validateService.ValidateTrue(); this.NavigationCacheMode = NavigationCacheMode.Disabled; this.Frame.Navigate(typeof(Login)); } catch (Exception exception) { MessageDialog dialog = new MessageDialog(exception.Message); await dialog.ShowAsync(); } } else { validateService.ValidateFalse(FirstNameMessage, errors, "firstName"); validateService.ValidateFalse(LastNameMessage, errors, "lastName"); validateService.ValidateFalse(EmailMessage, errors, "email"); validateService.ValidateFalse(PasswordMessage, errors, "password"); validateService.ValidateFalse(BirthdayMessage, errors, "birthday"); validateService.ValidateFalse(AvatarUrlMessage, errors, "avatar"); validateService.ValidateFalse(PhoneMessage, errors, "phone"); validateService.ValidateFalse(AddressMessage, errors, "address"); } }