Exemple #1
0
        async void updateProfile(object sender, EventArgs e)
        {
            if (jobseeker == null & admin == null)
            {
                string address  = addressData.Text.TrimEnd();
                string contact  = contactData.Text.TrimEnd();
                string password = passwordData.Text.TrimEnd();
                string email    = emailData.Text.TrimEnd();

                Regex whitespaceregex = new Regex(@"\s{1,}");
                Regex namelimit1regex = new Regex("[A-Za-z0-9]{50,}");
                Regex contactregex    = new Regex("[A-Za-z]{1,}");
                Regex emailregex      = new Regex("[@]{1,}");

                if (string.IsNullOrEmpty(address) || string.IsNullOrEmpty(contact) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
                {
                    await DisplayAlert("Alert Message", "Please fill up all the details.", "Cancel");
                }
                else
                {
                    if (address.Length > 100)
                    {
                        await DisplayAlert("Alert Message", "Maximum 100 characters is allowed for company's address.", "Cancel");
                    }
                    else
                    {
                        if (whitespaceregex.IsMatch(contact) || whitespaceregex.IsMatch(password) || whitespaceregex.IsMatch(email))
                        {
                            await DisplayAlert("Alert Message", "No space is allowed for Username, Password, Email and Contact.", "Cancel");
                        }
                        else
                        {
                            if (contactregex.IsMatch(contact) || contact.Length > 20)
                            {
                                await DisplayAlert("Alert Message", "Maximum 20 numeric characters is allowed for contact.", "Cancel");
                            }
                            else
                            {
                                if (namelimit1regex.IsMatch(password) || password.Length > 50)
                                {
                                    await DisplayAlert("Alert Message", "Maximum 50 alphanumeric characters is allowed for Password.", "Cancel");
                                }
                                else
                                {
                                    if (!(emailregex.IsMatch(email)))
                                    {
                                        await DisplayAlert("Alert Message", "Missing '@' for Email.", "Cancel");
                                    }
                                    else
                                    {
                                        Enterprise user   = new Enterprise(enterprise.CompanyName, enterprise.CompanyID, address, contact, enterprise.Username, password, email, enterprise.Status, enterprise.Remark, enterprise.PhotoName);
                                        var        update = await entmanager.UpdateEnterprise(user);

                                        if (update != null)
                                        {
                                            await DisplayAlert("Update Complete", "Profile updated successfully.", "Cancel");

                                            await Navigation.PopModalAsync();
                                        }
                                        else
                                        {
                                            await DisplayAlert("Update Failed", "Profile fail to update.", "Cancel");

                                            await Navigation.PopModalAsync();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (admin != null)
            {
                string userstatus = statusData.Items[statusData.SelectedIndex];

                Enterprise user   = new Enterprise(enterprise.CompanyName, enterprise.CompanyID, enterprise.CompanyAddress, enterprise.CompanyContact, enterprise.Username, enterprise.Password, enterprise.Email, userstatus, enterprise.Remark, enterprise.PhotoName);
                var        update = await entmanager.UpdateEnterprise(user);

                if (update != null)
                {
                    await DisplayAlert("Update Complete", "Profile updated successfully.", "Cancel");

                    await Navigation.PopModalAsync();
                }
                else
                {
                    await DisplayAlert("Update Failed", "Profile fail to update.", "Cancel");

                    await Navigation.PopModalAsync();
                }
            }
        }