public async Task <ActionResult <MobileUsers> > PostMobileUsers(MobileUsers mobileUsers) { var user = await _context.MobileUsers.Where(m => (m.FName == mobileUsers.FName) && (m.Lname == mobileUsers.Lname) && (m.Code == mobileUsers.Code) && (m.date == mobileUsers.date)).ToListAsync(); var homeCode = await _context.HomeCodes.Where(m => m.Code == mobileUsers.Code).ToListAsync(); //Only register a user if they use a valid, pre-exisiting home code if (homeCode.Count() != 0 && user.Count() == 0) { HomeCodes hc = homeCode.Find(m => m.Code == mobileUsers.Code); mobileUsers.address = hc.Address; _context.MobileUsers.Add(mobileUsers); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMobileUsers", new { id = mobileUsers.Id }, mobileUsers)); } else if (homeCode.Count() != 0 && user.Count() != 0) { //User is already created, send back a message stating so mobileUsers.Id = -1; return(CreatedAtAction("GetMobileUsers", new { id = "-1" }, mobileUsers)); } else { return(NotFound()); } }
public bool RegisterMobileUser(MobileUsers user) { bool insertResult = false; try { string insertMobileUser = "******" + " VALUES('" + user.CustomerName.Format_Sql_String() + "','" + user.MobileNo.Format_Sql_String() + "','" + user.Pin + "','" + user.tbl_CustomerId + "','" + user.CustomerNo.Format_Sql_String() + "','" + user.Email.Format_Sql_String() + "','" + user.IdNo.Format_Sql_String() + "','" + ValueConverters.FormatSqlDate(DateTime.Now) + "','" + ValueConverters.ConvertNullToBool(user.Enabled) + "'); "; int result = mainDb.Database.ExecuteSqlCommand(insertMobileUser); if (result >= 1) { insertResult = true; } } catch (Exception ex) { //log ex } return(insertResult); }
public async Task <IActionResult> Edit(int id, [Bind("Id,FName,Lname,Code,address")] MobileUsers mobileUsers) { if (id != mobileUsers.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mobileUsers); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MobileUsersExists(mobileUsers.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mobileUsers)); }
public async void PostUserInfo(String userHomeCode, String userFirstName, String userLastName) { // Set up new HttpClientHandler and its credentials so we can perform the web request HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); }; // Create new httpClient using our client handler created above HttpClient httpClient = new HttpClient(clientHandler); String apiUrl = "https://habitathomeownerbuddy.azurewebsites.net/api/MobileUsersAPI"; // Create new URI with the API url so we can perform the web request var uri = new Uri(string.Format(apiUrl, string.Empty)); MobileUsers user = new MobileUsers(); user.FName = userFirstName; user.Lname = userLastName; user.Code = userHomeCode; string JSONresult = JsonConvert.SerializeObject(user); var content = new StringContent(JSONresult, Encoding.UTF8, "application/json"); HttpResponseMessage response = await httpClient.PostAsync(apiUrl, content); // Keep track of id from the database - will be used to unregister home if (response.IsSuccessStatusCode) { // Get response from POST request var tokenJson = await response.Content.ReadAsStringAsync(); var array = tokenJson.Split('"'); String id = array[2]; id = id.Substring(1); id = id.TrimEnd(','); if (id != "-1") { String address = array[17]; // Save the id in preferences //This is where we store the home code and name, we are going to use Preferences to see if a user is logged in Preferences.Set("user_home_code", userHomeCode); Preferences.Set("user_first_name", userFirstName); Preferences.Set("user_last_name", userLastName); Preferences.Set("user_id", id); Preferences.Set("user_address", address); await Navigation.PushAsync(new HomePage(Preferences.Get("user_first_name", ""))); } else { await DisplayAlert("User Already Exists", "This user has already been registered on another phone, please unregister before continuing", "OK"); } } else { await DisplayAlert("Home Code does not exist", "Please double check your home code", "OK"); } }
public bool RegisterCustomer(MobileUsers user) { bool insertResult = false; insertResult = customerAccountsManager.RegisterMobileUser(user); return(insertResult); }
public async Task <IActionResult> Create([Bind("Id,FName,Lname,Code,address")] MobileUsers mobileUsers) { if (ModelState.IsValid) { _context.Add(mobileUsers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mobileUsers)); }
private MobileUsers FindMobileAccount(string mobileNo) { MobileUsers user = new MobileUsers(); try { String query = @"SELECT CustomerName,MobileNo,Pin,IdNo,tbl_CustomerId, CustomerNo,Email,Enabled,DateCreated FROM tbl_MobileUsers WHERE MobileNo = " + mobileNo.Format_Sql_String() + " ;"; user = this.mainDb.Database.SqlQuery <MobileUsers>(query).FirstOrDefault(); } catch (Exception ex) { //LOG ex } return(user); }
public LoginInfo Login(Login login) { LoginInfo loginInfo = new LoginInfo(); MobileUsers user = FindMobileAccount(login.MobileNo); //No user was found if (user == null) { loginInfo.Message = "Account not found"; loginInfo.Status = "Failed"; loginInfo.User = null; } else { if (user.tbl_CustomerId == Guid.Empty || user.Enabled == false) { //account pending activation loginInfo.Message = "Account pending activation"; loginInfo.Status = "Failed"; loginInfo.User = null; } else if (user.Pin.ToString().Trim() != login.Pin.ToString().Trim()) { //password not matching loginInfo.Message = "Invalid account details"; loginInfo.Status = "Failed"; loginInfo.User = null; } else { loginInfo.Message = "Welcome"; loginInfo.Status = "Success"; loginInfo.User = user; } } return(loginInfo); }
public async void getReminder() { // Grab user ID to send as a get message for user reminders string userId = Preferences.Get("user_id", "no address found"); // Set up new HttpClientHandler and its credentials so we can perform the web request HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); }; // Create new httpClient using our client handler created above HttpClient httpClient = new HttpClient(clientHandler); String apiUrl = "https://habitathomeownerbuddy.azurewebsites.net/api/MaintenanceReminderAPI/" + userId; String postApiUrl = "https://habitathomeownerbuddy.azurewebsites.net/api/MaintenanceReminderAPI"; // Create new URI with the API url so we can perform the web request var uri = new Uri(string.Format(apiUrl, string.Empty)); // Grab the current users information to call the post method for checking all user due dates MobileUsers user = new MobileUsers(); user.FName = Preferences.Get("user_first_name", "no first name found"); user.Lname = Preferences.Get("user_last_name", "no last name found"); user.Code = Preferences.Get("user_home_code", "no home code found"); string regDate = DateTime.Today.ToString("MM/dd/yyyy"); user.date = regDate; string JSONresult = JsonConvert.SerializeObject(user); Console.WriteLine(JSONresult); var content = new StringContent(JSONresult, Encoding.UTF8, "application/json"); HttpResponseMessage postResponse = await httpClient.PostAsync(postApiUrl, content); // Check if the POST web request was successful if (postResponse.IsSuccessStatusCode) { // Get web request response and store it var getResponse = await httpClient.GetAsync(uri); // Check if the GET web request was successful if (getResponse.IsSuccessStatusCode) { // Get the JSON object returned from the web request var userContent = await getResponse.Content.ReadAsStringAsync(); var reminders = JsonConvert.DeserializeObject <List <ReminderModel> >(userContent); ImageSource OverDueIcon = ImageSource.FromResource("HOB_Mobile.Resources.over_due.png"); ImageSource ToDoIcon = ImageSource.FromResource("HOB_Mobile.Resources.to_do_icon.png"); ImageSource DoneIcon = ImageSource.FromResource("HOB_Mobile.Resources.done_icon.png"); var OverDues = new List <ReminderModel>(); var ToDos = new List <ReminderModel>(); var Dones = new List <ReminderModel>(); foreach (ReminderModel reminder in reminders) { if (reminder.completed.Equals("Due")) { reminder.icon = ToDoIcon; ToDos.Add(reminder); } else if (reminder.completed.Equals("Completed")) { reminder.icon = DoneIcon; Dones.Add(reminder); } else if (reminder.completed.Equals("Overdue")) { reminder.icon = OverDueIcon; OverDues.Add(reminder); } else { // Not in season so don't display } } OverDues = OverDues.OrderBy(o => o.dueDate).ToList(); ToDos = ToDos.OrderBy(td => td.dueDate).ToList(); Dones = Dones.OrderByDescending(d => d.lastCompleted).ToList(); if (OverDues.Count.Equals(0)) { pastdues.Text = "You have no overdue tasks"; OverDueFrame.HeightRequest = 10; } else { OverDue.ItemsSource = OverDues; } if (ToDos.Count.Equals(0)) { todos.Text = "You have no maintenance tasks to do"; ToDoFrame.HeightRequest = 10; } else { ToDo.ItemsSource = ToDos; } if (Dones.Count.Equals(0)) { finished.Text = "You haven't done any maintenance tasks yet"; DoneFrame.HeightRequest = 10; } else { Done.ItemsSource = Dones; } } else { // This prints to the Visual Studio Output window Debug.WriteLine("Response not successful"); } } else { // This prints to the Visual Studio Output window Debug.WriteLine("Response not successful"); } }
public async void PostUserInfo(String userHomeCode, String userFirstName, String userLastName) { // Set up new HttpClientHandler and its credentials so we can perform the web request HttpClientHandler clientHandler = new HttpClientHandler(); clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return(true); }; // Create new httpClient using our client handler created above HttpClient httpClient = new HttpClient(clientHandler); String apiUrl = "https://habitathomeownerbuddy.azurewebsites.net/api/MobileUsersAPI"; String maintenanceApiUrl = "https://habitathomeownerbuddy.azurewebsites.net/api/MaintenanceReminderAPI"; // Create new URI with the API url so we can perform the web request var uri = new Uri(string.Format(apiUrl, string.Empty)); MobileUsers user = new MobileUsers(); user.FName = userFirstName; user.Lname = userLastName; user.Code = userHomeCode; string regDate = DateTime.Today.ToString("MM/dd/yyyy"); user.date = regDate; user.Instanceid = Preferences.Get("Instanceid", ""); string JSONresult = JsonConvert.SerializeObject(user); Console.WriteLine(JSONresult); var content = new StringContent(JSONresult, Encoding.UTF8, "application/json"); HttpResponseMessage response = await httpClient.PostAsync(apiUrl, content); // Keep track of id from the database - will be used to unregister home if (response.IsSuccessStatusCode) { // Get response from POST request var tokenJson = await response.Content.ReadAsStringAsync(); Console.WriteLine(tokenJson); var array = tokenJson.Split('"'); String id = array[2]; id = id.Substring(1); id = id.TrimEnd(','); if (id != "-1") { String address = array[17]; // Save the id in preferences //This is where we store the home code and name, we are going to use Preferences to see if a user is logged in Preferences.Set("user_home_code", userHomeCode); Preferences.Set("user_first_name", userFirstName); Preferences.Set("user_last_name", userLastName); Preferences.Set("user_id", id); Preferences.Set("user_address", address); Preferences.Set("user_register_date", regDate); //await Navigation.PushAsync(new HomePage(Preferences.Get("user_first_name", ""))); int newId = Int32.Parse(Preferences.Get("user_id", "no user id found")); user.Id = newId; string JSONresult2 = JsonConvert.SerializeObject(user); Console.WriteLine(JSONresult2); var content2 = new StringContent(JSONresult2, Encoding.UTF8, "application/json"); // Send this user's data to the maintenance reminder api to have the current maintenance reminders tied to their id HttpResponseMessage maintenanceResponse = await httpClient.PostAsync(maintenanceApiUrl, content2); if (maintenanceResponse.IsSuccessStatusCode) { Debug.WriteLine("SUCCESS"); } else { // This prints to the Visual Studio Output window Debug.WriteLine("Response not successful"); } // Sets the Home Page as the MainPage so when the physical back button is pressed immediately after registering, the app closes instead of returning to the Register Page Application.Current.MainPage = new NavigationPage(new Views.HomePage(Preferences.Get("user_first_name", ""))); } else { await DisplayAlert("User Already Exists", "This user has already been registered on another phone, please unregister before continuing", "OK"); } } else { await DisplayAlert("Home Code does not exist", "Please double check your home code", "OK"); } }