protected override ValidationResult IsValid(object value, ValidationContext validationContext) { VisaApplication V = (VisaApplication)validationContext.ObjectInstance; DateTime D = Convert.ToDateTime(value); if (V.Status == "Approved") { if (D >= DateTime.Today) { return(ValidationResult.Success); } else { return(new ValidationResult("Date Of Application Cannot be before the current date")); } } else { return(ValidationResult.Success); } }
//This method validates the details given by the user to cancel the visa application //If validation is successfult then it calculates cancellation charges and updates status as 'Cancelled' in database public static VisaApplication VisaCancellation(VisaApplication V) { try { //Checks whether the details entered by the user matches in the database VisaApplication VA = (from c in P.VisaApplications where c.UserID == V.UserID && c.VisaID == V.VisaID && c.PassportNumber == V.PassportNumber && c.DateOfIssue == V.DateOfIssue select c).FirstOrDefault(); if (VA != null) { int cancellationcost = 0; //Calculates difference between DateOfExpiry and Today's date in months int Diff_mon = 0; if (DateTime.Today < VA.DateOfExpiry) { Diff_mon = Math.Abs((VA.DateOfExpiry.Month - DateTime.Today.Month) + 12 * (VA.DateOfExpiry.Year - DateTime.Today.Year)); } //Calculates cancellation cost based on occupation and 'Diff_mon' if (VA.Occupation == "Student") { if (Diff_mon < 6) { cancellationcost = (int)(0.15 * VA.RegistrationCost); } else if (Diff_mon >= 6) { cancellationcost = (int)(0.25 * VA.RegistrationCost); } } else if (VA.Occupation == "Private Employee") { if (Diff_mon < 6) { cancellationcost = (int)(0.15 * VA.RegistrationCost); } else if (Diff_mon >= 6 && Diff_mon < 12) { cancellationcost = (int)(0.25 * VA.RegistrationCost); } else if (Diff_mon >= 12) { cancellationcost = (int)(0.20 * VA.RegistrationCost); } } else if (VA.Occupation == "Government Employee") { if (Diff_mon >= 6 && Diff_mon < 12) { cancellationcost = (int)(0.20 * VA.RegistrationCost); } else if (Diff_mon >= 12) { cancellationcost = (int)(0.25 * VA.RegistrationCost); } else if (Diff_mon < 6) { cancellationcost = (int)(0.15 * VA.RegistrationCost); } } else if (VA.Occupation == "Self Employed") { if (Diff_mon < 6) { cancellationcost = (int)(0.15 * VA.RegistrationCost); } else if (Diff_mon >= 6) { cancellationcost = (int)(0.25 * VA.RegistrationCost); } } else if (VA.Occupation == "Retired Employee") { if (Diff_mon < 6) { cancellationcost = (int)(0.10 * VA.RegistrationCost); } else if (Diff_mon >= 6) { cancellationcost = (int)(0.20 * VA.RegistrationCost); } } //Updating into database VA.CancellationCharges = cancellationcost; VA.Status = "Cancelled"; P.SaveChanges(); return(VA); } else { return(null); } } catch (Exception) { } return(null); }
//This method generates VisaID,DateOfIssue,DateOfExpiry and RegistrationCost based on validations and conditions mentioned in the SRD and insert in database public static VisaApplication VisaApply(VisaApplication V) { try { string visaid = string.Empty; //Calculates DateOfIssue basedon DateOfApplication DateTime IssueDate = V.DateOfApplication.AddDays(10); DateTime ExpiryDate = DateTime.Today; int registrationcost = 0; //Checks whether the User Entered PassportNumber is in database or not PassportApplication PA = (from c in P.PassportApplications where c.PassportNumber == V.PassportNumber select c).FirstOrDefault(); if (PA != null) { //Based on Occupation of the User UserID,ExpiryDate and RegistrationCost is generated if (V.Occupation == "Student") { int student_visaid = (from c in P.VisaApplications where c.Occupation == V.Occupation select c).Count() + 1; visaid = V.Occupation.Substring(0, 3).ToUpper() + "-" + string.Format("{0:0000}", student_visaid); ExpiryDate = IssueDate.AddYears(2); if (V.Country == "USA") { registrationcost = 3000; } else if (V.Country == "China") { registrationcost = 1500; } else if (V.Country == "Japan") { registrationcost = 3500; } } else if (V.Occupation == "Private Employee") { int pe_visaid = (from c in P.VisaApplications where c.Occupation == V.Occupation select c).Count() + 1; visaid = "PE-" + string.Format("{0:0000}", pe_visaid); ExpiryDate = IssueDate.AddYears(3); if (V.Country == "USA") { registrationcost = 4500; } else if (V.Country == "China") { registrationcost = 2000; } else if (V.Country == "Japan") { registrationcost = 4000; } } else if (V.Occupation == "Government Employee") { int ge_visaid = (from c in P.VisaApplications where c.Occupation == V.Occupation select c).Count() + 1; visaid = "GE-" + string.Format("{0:0000}", ge_visaid); ExpiryDate = IssueDate.AddYears(4); if (V.Country == "USA") { registrationcost = 5000; } else if (V.Country == "China") { registrationcost = 3000; } else if (V.Country == "Japan") { registrationcost = 4500; } } else if (V.Occupation == "Self Employed") { int se_visaid = (from c in P.VisaApplications where c.Occupation == V.Occupation select c).Count() + 1; visaid = "SE-" + string.Format("{0:0000}", se_visaid); ExpiryDate = IssueDate.AddYears(1); if (V.Country == "USA") { registrationcost = 6000; } else if (V.Country == "China") { registrationcost = 4000; } else if (V.Country == "Japan") { registrationcost = 9000; } } else if (V.Occupation == "Retired Employee") { int re_visaid = (from c in P.VisaApplications where c.Occupation == V.Occupation select c).Count() + 1; visaid = "RE-" + string.Format("{0:0000}", re_visaid); ExpiryDate = IssueDate.AddYears(1).AddMonths(6); if (V.Country == "USA") { registrationcost = 2000; } else if (V.Country == "China") { registrationcost = 2000; } else if (V.Country == "Japan") { registrationcost = 1000; } } //If ExpiryDate of Visa is after the ExpiryDate of Passport then ExpiryDate of Visa is updated to ExpiryDate of Passport if (ExpiryDate > PA.ExpiryDate) { ExpiryDate = PA.ExpiryDate; } //Inserting into database V.VisaID = visaid; V.DateOfIssue = IssueDate; V.DateOfExpiry = ExpiryDate; V.RegistrationCost = registrationcost; P.VisaApplications.Add(V); P.SaveChanges(); return(V); } else { return(null); } } catch (Exception) { } return(null); }