async void OnDismiss(object sender, EventArgs e) { Button button = (Button)sender; button.IsEnabled = false; this.IsBusy = true; try { int Id = 0; string status = "Pending"; int jobid = jobdetail.Id; if (jobseeker != null) { string proposal = proposalCell.Text.TrimEnd(); if (string.IsNullOrEmpty(proposal)) { await DisplayAlert("Alert Message", "Please fill up the proposal.", "Cancel"); } else if (proposalCell.Text.Length > 200) { await DisplayAlert("Alert Message", "Porposal statement should not be more than 200 characters.", "Cancel"); } else { int count = 0; var checkjs = await jsmanager.GetApplyJob(jobseeker.Username); foreach (Submission applied in checkjs) { if (applies.All(b => b.Id != applied.Id)) { if (applied.Jobid == jobdetail.Id) { applies.Add(applied); count++; } } } if (count == 0) { //apply Submission submission = new Submission(Id, status, proposal, jobdetail.Title, jobid, jobseeker.Name, jobseeker.Username); var submit = await jsmanager.CreateSubmission(submission); if (submit != null) { await DisplayAlert("Apply Successful", "Application submitted.", "Cancel"); await Navigation.PopModalAsync(); } else { await DisplayAlert("Apply Failed", "Application fail to submit. Something wents wrong.", "Cancel"); await Navigation.PopModalAsync(); } } else { await DisplayAlert("Apply Failed", "You have already apply for this job.", "Cancel"); await Navigation.PopModalAsync(); } } } else { string description = descriptionCell.Text.TrimEnd(); string convert = salaryCell.Text.TrimEnd(); string salarytype = salaryType.Items[salaryType.SelectedIndex]; string jobstatus = Status.Items[Status.SelectedIndex]; if (string.IsNullOrEmpty(description) || string.IsNullOrEmpty(convert)) { await DisplayAlert("Alert Message", "Please fill up the job description and salary.", "Cancel"); } else { try { decimal salary1 = decimal.Parse(convert); decimal salary = Math.Round(salary1, 2); if (salary <= 0 || salary > 210000) { await DisplayAlert("Alert Message", "Salary must be greater than 0 and lesser than 210,000.", "Cancel"); } else { if (jobstatus.Equals("End")) { if (await this.DisplayAlert("End Job?", "You can't change the job details anymore once you have end the job's status. Are you sure, you still want to proceed?", "Yes", "Cancel") == true) { //update Job job = new Job(jobdetail.Id, jobdetail.Title, description, salary, salarytype, jobstatus, jobdetail.Entusername); var update = await entmanager.UpdateJob(job); if (update != null) { await DisplayAlert("Update Successful", "Application updated.", "Cancel"); await Navigation.PopModalAsync(); } else { await DisplayAlert("Update Failed", "Application fail to update.", "Cancel"); await Navigation.PopModalAsync(); } } } else { //update Job job = new Job(jobdetail.Id, jobdetail.Title, description, salary, salarytype, jobstatus, jobdetail.Entusername); var update = await entmanager.UpdateJob(job); if (update != null) { await DisplayAlert("Update Successful", "Application updated.", "Cancel"); await Navigation.PopModalAsync(); } else { await DisplayAlert("Update Failed", "Application fail to update.", "Cancel"); await Navigation.PopModalAsync(); } } } } catch (Exception ex) { await DisplayAlert("Alert Message", "Something wents wrong.", "Cancel"); } } } } finally { this.IsBusy = false; button.IsEnabled = true; } }