public async Task <JToken> createStudAccount()
        {
            //Populate regiatration data
            System.Diagnostics.Debug.WriteLine(" In create student account " + regAccount.UserName);
            regAccount.AccountID = cdUserName.Text;
            System.Diagnostics.Debug.WriteLine(" In create student account " + regAccount.AccountID);
            regAccount.UserName     = cdUserName.Text;
            regAccount.EmailAddress = cdEmail.Text;
            regAccount.FirstName    = cdFirstName.Text;
            regAccount.LastName     = cdLastName.Text;
            regAccount.AddressLine1 = cdAddress1.Text;
            regAccount.AddressLine2 = "None";
            regAccount.City         = cdCity.Text;
            regAccount.cdState      = cdState.Text;
            regAccount.PostalCode   = cdPostalCode.Text;
            regAccount.Phone        = cdPhone.Text;
            regAccount.MiddleName   = "None";
            if (cdPhone.Text == null)
            {
                regAccount.Phone = "None";
            }

            if (regAccount.UserName == null ||
                regAccount.FirstName == null ||
                regAccount.AddressLine1 == null ||
                regAccount.cdState == null ||
                regAccount.City == null ||
                regAccount.PostalCode == null ||
                regAccount.EmailAddress == null ||
                regAccount.LastName == null)
            {
                await DisplayAlert("Action", "Key attributes cannot be null. Please go to personal information and enter the same", "Ok");

                return("failed");
            }
            else
            {
                regAccount.AccountStatus = "Approved";
                regAccount.AddressLine3  = "None";
                regAccount.County        = "NA";
                regAccount.Destination   = "NA";
                regAccount.ParentID      = myAccount.UserName;
                regAccount.Role          = regAccount.Role + "R";
                regAccount.School        = "None";
                regAccount.SchoolID      = "None";
                regAccount.Teacher       = "None";
                regAccount.Attr1         = "NA";
                regAccount.Attr2         = "NA";
                regAccount.Attr3         = "NA";
                regAccount.Attr4         = "NA";
                regAccount.Attr5         = "NA";
                regAccount.Attr6         = "NA";
                regAccount.Attr7         = "NA";
                regAccount.Attr8         = "NA";
                regAccount.Attr9         = "NA";
                regAccount.Attr10        = "NA";
                try
                {
                    cdCallAPI mycallAPI  = new cdCallAPI();
                    var       jsresponse = await mycallAPI.cdcallAccountsPUT(regAccount);

                    if (jsresponse.ToString().Contains("ValidationException"))
                    {
                        System.Diagnostics.Debug.WriteLine(" Account creation call failed " + jsresponse);
                        var myerror = JsonConvert.DeserializeObject <cdReadError>(jsresponse.ToString());
                        return("failed " + myerror.message);
                    }
                    else
                    {
                        accCreated = 1;
                        signupAccount mysignupAccount = new signupAccount();
                        mysignupAccount.email    = cdEmail.Text;
                        mysignupAccount.username = cdUserName.Text;
                        mysignupAccount.password = cdPassword.Text;

                        var signupRespose = await mycallAPI.cdCreateSignup(mysignupAccount);

                        if (signupRespose.ToString().Contains("ValidationException"))
                        {
                            System.Diagnostics.Debug.WriteLine(" Account signup failed " + jsresponse);
                            var myerror = JsonConvert.DeserializeObject <cdReadError>(jsresponse.ToString());
                            await DisplayAlert("Login creation failed", "Login creation failed. " + jsresponse, "OK");

                            return("failed");
                        }

                        return("success");
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("End of Clubs Loop " + ex);
                    await DisplayAlert("Action", "Update Status Failed", "OK");

                    return("failed");
                }
            }
        }
Beispiel #2
0
        async void cdSubmit(object sender, System.EventArgs e)
        {
            int performSubmit = 0;

            System.Diagnostics.Debug.WriteLine(" Submit button clicked");
            cdCallAPI mycallAPI = new cdCallAPI();

            //Populate regiatration data
            if (regAccount.UserName == null ||
                regAccount.FirstName == null ||
                regAccount.EmailAddress == null ||
                regAccount.LastName == null)
            {
                await DisplayAlert("Action", "Key attributes cannot be null. Please go to personal information and enter the same", "Ok");

                performSubmit = 0;
            }
            else
            {
                performSubmit            = 1;
                regAccount.AccountID     = regAccount.UserName;
                regAccount.AccountStatus = "Approved";
                if (cdNewClub.IsChecked == true || cdCheckAdmin.IsChecked == true)
                {
                    regAccount.Role = "A";
                }
                if (cdCheckRider.IsChecked == true)
                {
                    regAccount.Role = regAccount.Role + "R";
                }
                regAccount.Attr1  = "None";
                regAccount.Attr2  = "None";
                regAccount.Attr3  = "None";
                regAccount.Attr4  = "None";
                regAccount.Attr5  = "None";
                regAccount.Attr6  = "None";
                regAccount.Attr7  = "None";
                regAccount.Attr8  = "None";
                regAccount.Attr9  = "None";
                regAccount.Attr10 = "None";
            }

            if (performSubmit == 1)
            {
                var jsresponse = await mycallAPI.cdcallAccountsPUT(regAccount);

                if (jsresponse.ToString().Contains("ValidationException"))
                {
                    System.Diagnostics.Debug.WriteLine(" Account creation call failed " + jsresponse);
                    var myerror = JsonConvert.DeserializeObject <cdReadError>(jsresponse.ToString());
                    cdStatus.Text = "Account Creation Failed because " + myerror.message;
                    await DisplayAlert("Account creation failed", cdStatus.Text, "OK");
                }
                else
                {
                    signupAccount mysignupAccount = new signupAccount();
                    mysignupAccount.email    = regAccount.EmailAddress;
                    mysignupAccount.username = regAccount.UserName;
                    mysignupAccount.password = regPassword;

                    var signupRespose = await mycallAPI.cdCreateSignup(mysignupAccount);

                    if (signupRespose.ToString().Contains("ValidationException"))
                    {
                        System.Diagnostics.Debug.WriteLine(" Account signup failed " + jsresponse);
                        var myerror = JsonConvert.DeserializeObject <cdReadError>(jsresponse.ToString());
                        cdStatus.Text = "Login creation failed. " + myerror.message;
                        await DisplayAlert("Login creation failed", cdStatus.Text, "OK");
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine(" Put API Call Successful");
                        if (cdNewClub.IsChecked == true)
                        {
                            regClub.ClubName = cdClubName.Text;
                            regClub.ClubID   = cdClubName.Text.Substring(0, 3) + (Math.Abs(DateTime.Now.ToBinary()).ToString());
                            regClub.ClubReg  = "NA";
                            regClub.Attr1    = "NA";
                            regClub.Attr2    = "NA";
                            regClub.Attr3    = "NA";
                            regClub.Attr4    = "NA";
                            regClub.Attr5    = "NA";
                            regClub.Attr6    = "NA";
                            regClub.Attr7    = "NA";
                            regClub.Attr8    = "NA";
                            regClub.Attr9    = "Approved";
                            regClub.Attr10   = "NA";

                            jsresponse = await mycallAPI.cdcallClubsPUT(regClub);

                            if (jsresponse.ToString().Contains("ValidationException"))
                            {
                                System.Diagnostics.Debug.WriteLine(" Club creation call failed " + jsresponse);
                                var myerror = JsonConvert.DeserializeObject <cdReadError>(jsresponse.ToString());
                                cdStatus.Text = "Club Creation Failed. " + myerror.message;
                                await DisplayAlert("Club creation failed", cdStatus.Text, "OK");
                            }
                            else
                            {
                                ClubMembers myclubmembership = new ClubMembers();
                                myclubmembership.ClubMemberID    = regAccount.UserName + regClub.ClubID;
                                myclubmembership.ClubID          = regClub.ClubID;
                                myclubmembership.MemberAccountID = regAccount.UserName;
                                myclubmembership.ClubName        = regClub.ClubName;
                                myclubmembership.MemberName      = regAccount.FirstName + " " + regAccount.LastName;
                                myclubmembership.MemberRole      = regAccount.Role;
                                myclubmembership.Attr1           = "NA";
                                myclubmembership.Attr2           = regAccount.EmailAddress;
                                myclubmembership.Attr3           = "NA";
                                myclubmembership.Attr4           = "NA";
                                myclubmembership.Attr5           = "NA";
                                myclubmembership.Attr6           = "NA";
                                myclubmembership.Attr7           = "NA";
                                myclubmembership.Attr8           = "NA";
                                myclubmembership.Attr9           = "NotApproved";
                                myclubmembership.Attr10          = "NA";

                                jsresponse = await mycallAPI.cdcallClubMemberPUT(myclubmembership);

                                if (jsresponse.ToString().Contains("ValidationException"))
                                {
                                    System.Diagnostics.Debug.WriteLine(" Club Membership creation call failed " + jsresponse);
                                    var myerror = JsonConvert.DeserializeObject <cdReadError>(jsresponse.ToString());
                                    cdStatus.Text = "Club Member Creation Failed. " + myerror.message;
                                    await DisplayAlert("Club Member creation failed", cdStatus.Text, "OK");
                                }
                                else
                                {
                                    await DisplayAlert("Action", "Registration Successful", "Ok");

                                    var bpage = new MainPage();
                                    await Navigation.PushModalAsync(bpage);
                                }
                            }
                        }
                    }
                }
            }
        }