/// <summary> /// its update or book , depend which method sent to the function. /// </summary> /// <param name="method">"Create" or "Edit"</param> private async void SubmitHanler(string method) { try { var book = this.Book; if (book.Price <= 0 && book.Copies <= 0 && String.IsNullOrWhiteSpace(book.Title) && String.IsNullOrEmpty(book.Title) && String.IsNullOrWhiteSpace(book.Publisher) && String.IsNullOrEmpty(book.Publisher)) { throw new Exception("You need enter a valid title, publisher , price and copies. Pleate try again!"); } if (String.IsNullOrWhiteSpace(book.Title) && String.IsNullOrEmpty(book.Title)) { throw new Exception("You need enter a valid title"); } if (String.IsNullOrWhiteSpace(book.Publisher) && String.IsNullOrEmpty(book.Publisher)) { throw new Exception("You need enter a valid publisher name. Pleate try again!"); } if (book.Price <= 0) { throw new Exception("You need enter a valid price(more than 1). Pleate try again!"); } if (book.Copies <= 0) { throw new Exception("You need enter a valid copies(more than 1). Pleate try again!"); } if (book.Discount < 0 || book.Discount > 100) { throw new Exception("You need enter a valid discount(between 0-100). Pleate try again!"); } book.SetDiscount(book.Discount); var json = JsonConvert.SerializeObject(book); HttpResponseMessage response = new HttpResponseMessage(); if (method == "edit/book") { response = await ApiService.EditItem(Client, method, json); } else if (method == "create/book") { response = await ApiService.PostItem(Client, method, json); } if (response.IsSuccessStatusCode) { NavigateTool.Nav(new MainLibraryPage()); } else { MessageBox.Show(response.Content.ReadAsStringAsync().Result); } } catch (Exception err) { MessageBox.Show(err.Message); } }
private void SearchItemsHandler() { try { NavigateTool.Nav(new SearchPage()); } catch (Exception err) { MessageBox.Show(err.Message); } }
private void CreateJornalHendler() { try { SelectedItem = new Jornal(); NavigateTool.Nav(new CreateJornalView()); } catch (Exception err) { MessageBox.Show(err.Message); } }
/// <summary> /// its update or jornal , depend which method sent to the function. /// </summary> /// <param name="method">"Create" or "Edit"</param> private async void SubmitHanler(string method) { try { var jornal = this.Jornal; if (jornal.Price <= 0 && String.IsNullOrEmpty(jornal.Title) && String.IsNullOrWhiteSpace(jornal.Title) && String.IsNullOrEmpty(jornal.Month) && String.IsNullOrWhiteSpace(jornal.Month)) { throw new Exception("You need enter a valid title , price and month. Pleate try again!"); } if (String.IsNullOrEmpty(jornal.Title) && String.IsNullOrWhiteSpace(jornal.Title)) { throw new Exception("You need enter a valid title. Pleate try again!"); } if (String.IsNullOrEmpty(jornal.Month) && String.IsNullOrWhiteSpace(jornal.Month)) { throw new Exception("You need enter a valid month. Pleate try again!"); } if (jornal.Price <= 0) { throw new Exception("You need enter a valid price(more than 1). Pleate try again!"); } jornal.SetDiscount(jornal.Discount); var json = JsonConvert.SerializeObject(jornal); HttpResponseMessage response = new HttpResponseMessage(); if (method == "edit/jornal") { response = await ApiService.EditItem(Client, method, json); } else if (method == "create/jornal") { response = await ApiService.PostItem(Client, method, json); } if (response.IsSuccessStatusCode) { NavigateTool.Nav(new MainLibraryPage()); } else { MessageBox.Show(response.Content.ReadAsStringAsync().Result); } } catch (Exception err) { MessageBox.Show(err.Message); } }
private async void Login() { try { if (String.IsNullOrEmpty(TextUser) || String.IsNullOrEmpty(Password)) { throw new Exception("Please type your username and password!"); } if (TextUser.Length < 3) { throw new Exception("Username must contains 3 letters and more!"); } if (Password.Length < 4) { throw new Exception("Password must contains 4 digits and more!"); } CanClick = false; var json = GetUser(TextUser.ToLower(), Password); var response = await PostUser("login", json); var userJson = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { Consts.ActiveUser = JsonConvert.DeserializeObject <LoginModel>(userJson); NavigateTool.NavFromLogin(); } else { MessageBox.Show("You entered wrong username/password!\nPlease try again."); CanClick = true; } } catch (Exception err) { MessageBox.Show(err.Message); CanClick = true; } }
private void EditItemHandler() { try { if (SelectedItem == null || String.IsNullOrEmpty(SelectedItem.Title)) { throw new Exception("You need select item before edit!"); } if (SelectedItem.GetType() == typeof(Book)) { NavigateTool.Nav(new CreateBook()); } if (SelectedItem.GetType() == typeof(Jornal)) { NavigateTool.Nav(new CreateJornalView()); } } catch (Exception err) { MessageBox.Show(err.Message); } }
private void DisconectedHandler() { ActiveUser = null; Consts.ActiveUser = null; NavigateTool.DisconectedNav(); }