//Student services
        async public Task <Student> CheckLogin(string UserID, string InsertedPassword)
        {
            if (CurrentConnection.Equals(NetworkAccess.Internet))
            {
                var StudentResult = await ApiResponse.GetStudent(UserID);

                return(StudentResult.Password == InsertedPassword ? StudentResult : null);
            }

            await NoInternetAlert();

            return(null);
        }
        public LoginPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
            : base(navigationService, pageDialogService)
        {
            ApiService = new ApiService();

            LoginCommand = new DelegateCommand(async() =>
            {
                IsBusy            = true;
                CurrentConnection = Connectivity.NetworkAccess;
                if (CurrentConnection.Equals(NetworkAccess.Internet))
                {
                    if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password))
                    {
                        await DialogService.DisplayAlertAsync("Fields can not be empty! Try again!", null, "Ok");
                    }
                    else
                    {
                        if (Username.Equals(MyUserCredential) && Password.Equals(MyPasswordCredential))
                        {
                            Contacts = await ApiService.GetRandomContacts();
                            //Contacts = new Contact();
                            var ContactsParameters = new NavigationParameters();
                            ContactsParameters.Add("AllContacts", Contacts);

                            await DialogService.DisplayAlertAsync($"Welcome '{Username.ToUpper()}' to \nYourContacts App!", null, "Ok");

                            await NavigationService.NavigateAsync(new Uri($"/{Constants.Navigation}/{Constants.TabbedPage}?selectedTab={Constants.Contact}",
                                                                          UriKind.Absolute), ContactsParameters);
                        }
                        else
                        {
                            await DialogService.DisplayAlertAsync("Invalid Login Credentials! Try again!", null, "Ok");
                        }
                    }
                }
                else
                {
                    await DialogService.DisplayAlertAsync("Check your internet Connection and Try Again!", null, "Ok");
                }

                IsBusy = false;
            });
        }
Example #3
0
        public async Task <HttpResponseMessage> ExecuteRequestAsync(HttpRequestMessage request)
        {
            var cts = new CancellationTokenSource();
            HttpResponseMessage response = new HttpResponseMessage();

            //check connectivity first
            if (_networkAccess.Equals(NetworkAccess.None))
            {
                var responseMsg = "There's no network connection";
                response.StatusCode = System.Net.HttpStatusCode.BadRequest;
                response.Content    = new StringContent(responseMsg);
                HelperFunctions.ShowToastMessage(ToastMessageType.Error, responseMsg);
                return(response);
            }

            response = await Policy
                       .Handle <HttpRequestException>()
                       .WaitAndRetryAsync
                       (
                retryCount: 1,
                sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
                       )
                       .ExecuteAsync(async() =>
            {
                Task <HttpResponseMessage> task = _client.SendAsync(request);
                runningTasks.Add(task.Id, cts);
                var result = task.Result;

                if (result.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    //Access token expired
                }
                runningTasks.Remove(task.Id);
                return(result);
            });

            return(response);
        }
Example #4
0
        public async Task <User> UserSignup(User newUser)
        {
            NetworkAccess networkAccess = Connectivity.NetworkAccess;

            if (networkAccess.Equals(NetworkAccess.Internet))
            {
                try
                {
                    var uri = new Uri(URLS.SignupUser);
                    var dob = newUser?.DateOfBirth != null ? $"{newUser.DateOfBirth:yyyy-MM-dd}" : $"{new DateTime():yyyy-MM-dd}";

                    if (newUser?.Username != null)
                    {
                        var parameters = new Dictionary <string, string>
                        {
                            { "username", newUser.Username },
                            { "email", newUser.Email },
                            { "password", newUser.Password },
                            { "firstname", newUser.FirstName },
                            { "lastname", newUser.LastName },
                            { "admin_role", ((int)newUser.AdminRole).ToString() },
                            { "account_type", newUser.AccountType.ToString() },
                            { "gender", newUser.Gender },
                            { "dob", dob },
                            { "phone", newUser.PhoneNo },
                            { "phone_verified", newUser.PhoneNoVerification },
                            { "country", newUser.Country },
                            { "state", newUser.State }
                        };
                        var encodedContent           = new FormUrlEncodedContent(parameters);
                        HttpResponseMessage response = await httpClient.PostAsync(uri, encodedContent);

                        if (response.IsSuccessStatusCode)
                        {
                            var content = await response.Content.ReadAsStringAsync();

                            JObject respBody = JObject.Parse(content);
                            if (respBody.TryGetValue("body", out body) && respBody.TryGetValue("error", out error))
                            {
                                if (body != null && body.HasValues)
                                {
                                    return(newUser);
                                }

                                if (error != null && error.HasValues)
                                {
                                    response.Dispose();
                                    httpClient.Dispose();
                                    return(null);
                                }
                            }
                        }
                    }
                    else
                    {
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(@"ERROR {0}", ex.Message);
                    httpClient.Dispose();
                    return(null);
                }

                httpClient.Dispose();
                return(null);
            }
            else
            {
                httpClient.Dispose();
                return(null);
            }
        }
Example #5
0
        //Student services
        async public Task <Student> CheckLogin(string UserID, string InsertedPassword)
        {
            if (CurrentConnection.Equals(NetworkAccess.Internet))
            {
                if (await ApiResponse.VerifyStudent(UserID, InsertedPassword))
                {
                    return(await ApiResponse.GetStudent(UserID));
                }

                return(null);
            }

            await NoInternetAlert();

            return(null);
        }
Example #6
0
        public ContactPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
            : base(navigationService, pageDialogService)
        {
            ApiService = new ApiService();

            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefreshing = true;

                CurrentConnection = Connectivity.NetworkAccess;
                if (CurrentConnection.Equals(NetworkAccess.Internet))
                {
                    await UpdateContacts();
                }

                IsRefreshing = false;
            });

            SearchCommand = new DelegateCommand(async() =>
            {
                if (FoundContact)
                {
                    FoundContact = false;
                }
                IsRefreshing = true;

                CurrentConnection = Connectivity.NetworkAccess;
                if (CurrentConnection.Equals(NetworkAccess.Internet))
                {
                    if (!String.IsNullOrEmpty(ContactID))
                    {
                        int id = Convert.ToInt32(ContactID);
                        if (id > 0)
                        {
                            SearchContact = await ApiService.GetContactsById(id);
                            if (SearchContact != null && !SearchContact.CatchError)
                            {
                                ShowContacts = false;
                                Cancel       = true;
                                FoundContact = true;
                                FullName     = $" {SearchContact.dob.age} | {SearchContact.name.ToString()} ";
                                Address01    = $"Country: {SearchContact.location.country.ToUpper()} \nCity: {SearchContact.location.city.ToUpper()}\nState: {SearchContact.location.state.ToUpper()} \nZIP: {SearchContact.location.postcode}\n";
                                Address02    = $"Street: {SearchContact.location.street.name} - {SearchContact.location.street.number} ";

                                IsRefreshing = false;
                                return;
                            }
                            else
                            {
                                await DialogService.DisplayAlertAsync("Connection Interruped! Try Again!", null, "Ok");
                            }

                            ContactID    = null;
                            Cancel       = false;
                            FoundContact = false;
                            ShowContacts = true;
                        }
                        else
                        {
                            await DialogService.DisplayAlertAsync("Invalid Value! Try Again!", null, "Ok");
                        }
                        Console.WriteLine();
                    }
                    else
                    {
                        await DialogService.DisplayAlertAsync("Field can not be empty! Try again!", null, "OK");
                    }
                }

                IsRefreshing = false;
            });

            CancelCommand = new DelegateCommand(async() =>
            {
                IsRefreshing = true;
                FoundContact = false;

                if (!String.IsNullOrEmpty(ContactID))
                {
                    await UpdateContacts();
                    ContactID    = null;
                    Cancel       = false;
                    ShowContacts = true;
                }

                IsRefreshing = false;
            });
        }