private async void SaveCustomer() { IRestDataMapper mapper = containerExtension.Resolve <IRestDataMapper>(); if (!string.IsNullOrEmpty(SelectedCustomer.name) && SelectedCustomer.id == 0) { SelectedCustomer.branch = loggedUser.LoggedUser.branch; CustomerCreditAccount ac = await CustomerCreditRestService .CreateCustomerCreditAccountAsync(mapper, new CustomerCreditAccount() { id = 0, totalCredit = 0.00m }); if (ac.id <= 0) { dialogService.ShowMsgDialog("New Customer Creation", "Can't Save Customer", MsgDialogType.error, (r) => { return; }); } SelectedCustomer.customerCreditAccount = ac; Customer c = await CustomerRestService.CreateCustomerAsync(mapper, SelectedCustomer); if (c.id > 0) { c.code = $"C{c.id}"; c = await CustomerRestService.UpdateCustomerAsync(mapper, c); if (c.id > 0 && !string.IsNullOrEmpty(c.code)) { dialogService.ShowMsgDialog("New Customer Creation", "Customer Created Successfully", MsgDialogType.infor, (r) => { LoadCustomersAsync(); NewCustomer(); }); } else { dialogService.ShowMsgDialog("New Customer Creation", "Can't Update Customer", MsgDialogType.error, (r) => { return; }); } } else { dialogService.ShowMsgDialog("New Customer Creation", "Can't Save Customer", MsgDialogType.error, (r) => { return; }); } } else { dialogService.ShowMsgDialog("New Customer Creation", "Invalid Customer Details or Already Exist Customer", MsgDialogType.warrning, (r) => { return; }); } }
private async void UpdateCustomer() { IRestDataMapper mapper = containerExtension.Resolve <IRestDataMapper>(); if (SelectedCustomer != null) { if (SelectedCustomer.id > 0) { Customer c = await CustomerRestService.UpdateCustomerAsync(mapper, SelectedCustomer); if (c != null) { if (c.id > 0) { dialogService.ShowMsgDialog("Customer Details Update", "Customer Update Successfully", MsgDialogType.infor, (r) => { LoadCustomersAsync(); NewCustomer(); }); } else { dialogService.ShowMsgDialog("Customer Details Update", "Can't Update Customer", MsgDialogType.error, (r) => { return; }); } } else { dialogService.ShowMsgDialog("Customer Details Update", "Can't Update Customer", MsgDialogType.error, (r) => { return; }); } } else { dialogService.ShowMsgDialog("Customer Details Update", "Please Select Customer Before Update", MsgDialogType.warrning, (r) => { return; }); } } else { dialogService.ShowMsgDialog("Customer Details Update", "Please Select Customer Before Update", MsgDialogType.warrning, (r) => { return; }); } }
/* * Function that runs when user clicks login. Uses the LoginService class to login a user and get their * information from the database. Depending on the type of user that logs in, it redirects them to the * appropriate page and also saves some information in persistent storage for future use. */ async void Login() { LoginService loginService = new LoginService(Email, Password); CustomerRestService customerRestService = new CustomerRestService(); try { await loginService.Login(); Account retrieved_user = await loginService.GetUserFromDatabase(); int account_level_id = retrieved_user.AccountLevelID; int account_id = retrieved_user.AccountID; // Save information in persistent storage Application.Current.Properties["isLoggedIn"] = Boolean.TrueString; Application.Current.Properties["accountLevelID"] = account_level_id; Application.Current.Properties["accountID"] = account_id; // If statement depending on the type of user that logged in (Admin, Care Partner, or Customer) if (account_level_id == 1) { Application.Current.MainPage.Navigation.InsertPageBefore(new AdminNavBar(), Application.Current.MainPage.Navigation.NavigationStack[0]); await Application.Current.MainPage.Navigation.PopToRootAsync(); } else if (account_level_id == 2) { CarePartner carePartner = await new CarePartnerRestService().GetCarePartnerByAccountIDAsync(account_id); Application.Current.Properties["carePartnerID"] = carePartner.CarePartnerID; Application.Current.MainPage.Navigation.InsertPageBefore(new CarePartnerNavBar(), Application.Current.MainPage.Navigation.NavigationStack[0]); await Application.Current.MainPage.Navigation.PopToRootAsync(); } else if (account_level_id == 3) // if the user is a customer { var retrieved_customer = await customerRestService.GetCustomerByAccountIDAsync(account_id); int customer_id = retrieved_customer[0].CustomerID; Application.Current.Properties["customerID"] = customer_id; // Store CustomerID in persistent storage Application.Current.MainPage.Navigation.InsertPageBefore(new CustomerNavBar(), Application.Current.MainPage.Navigation.NavigationStack[0]); await Application.Current.MainPage.Navigation.PopToRootAsync(); } } catch (Exception e) { await Application.Current.MainPage.DisplayAlert("Error", e.Message, "OK"); } }
private async void LoadCustomersAsync() { IRestDataMapper mapper = containerExtension.Resolve <IRestDataMapper>(); SourceCustomers = await CustomerRestService.GetCustomerByBranchIdAsync(mapper, loggedUser.LoggedUser.branch.id); }