public async Task <ActionResult <CarePartner> > PostCarePartner(CarePartner carePartner) { _context.CarePartners.Add(carePartner); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCarePartner", new { id = carePartner.CarePartnerID }, carePartner)); }
public async Task <IActionResult> PutCarePartner(int id, CarePartner carePartner) { if (id != carePartner.CarePartnerID) { return(BadRequest()); } _context.Entry(carePartner).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CarePartnerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task SaveCarePartnerAsync(CarePartner item, bool isNewItem = false) { var uri = new Uri(string.Format(Constants.CarePartnersUrl, string.Empty)); try { var json = JsonConvert.SerializeObject(item); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; if (isNewItem) { response = await _client.PostAsync(uri, content); } else { response = await _client.PutAsync(uri, content); } if (response.IsSuccessStatusCode) { Debug.WriteLine(@"\tCare Partner successfully saved."); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR {0}", ex.Message); } }
/* * 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"); } }
public async Task <CarePartner> GetCarePartnerByAccountIDAsync(int accountID) { CarePartner CarePartners = new CarePartner(); var uri = new Uri(string.Format(Constants.CarePartnerAccountIDUrl, accountID)); try { var response = await _client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); CarePartners = JsonConvert.DeserializeObject <CarePartner>(content); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR {0}", ex.Message); } return(CarePartners); }