private static IEnumerable <DateTime> WorkingDays(this DateTime self, DateTime toDate, bool isAdmin) { if (isAdmin) { var adminRange = Enumerable.Range(0, new TimeSpan(toDate.Ticks - self.Ticks).Days); return(from i in adminRange let date = self.Date.AddDays(i) select date); } var holidays = from dt in BLL.Holidays.List select dt.NextHoliday; var weekends = new List <DayOfWeek> { DayOfWeek.Saturday, DayOfWeek.Sunday }; var maxedOutdates = EmbassyAppDb.GetClosedApptDates(EmWebAppConfig.QueueDailyMax); // skip today var range = Enumerable.Range(1, new TimeSpan(toDate.Ticks - self.Ticks).Days); return(from i in range let date = self.Date.AddDays(i) where !weekends.Contains(date.DayOfWeek) && !holidays.Contains(date) && !maxedOutdates.Contains(date) select date); }
public ActionResult Index([Bind(Include = "AppointmentDate,AppointmentType,Name,Gender,DateOfBirth,PlaceOfBirth,Nationality,NRIC_No,PassportNumber,PassportIssuedDate,ConsulateLocation,StayType,StayPermitNumber,EmployerName,Occupation,ContactAddr1,ContactAddr2,ContactPhone,ContactEmail,HomeAddr1,HomeAddr2,HomePhone,Note")] ConsularApptVM consularApptVM) { if (!ModelState.IsValid) { this.LogModelStateError(); } ViewBag.Title = "Embassy Consular Appointment Form (Admin)"; consularApptVM.Note = "[ADMIN]" + consularApptVM.Note; EmbassyAppDb.AddConsularAppt(consularApptVM, EmWebAppConfig.QueueNumberInitial); DateTime? confirmedApptDate = null; int? confirmedQueNumber = 0; ConsularApptVM consularApptVM2 = EmbassyAppDb.ConfirmConsularAppt(consularApptVM.Id, consularApptVM.ActivationCode, ref confirmedApptDate, ref confirmedQueNumber); consularApptVM.QueueNumber = confirmedQueNumber.GetValueOrDefault(); ViewBag.PartialHtml = "_MsgApptConfirmedByAdmin"; AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(consularApptVM.AppointmentType); ViewBag.AppointmentType = appointmentType.Description; return(View(consularApptVM)); }
public static SelectList GetAppointmentDates() { var ldt = EmbassyAppDb.GetApptDates(); var list = from dt in ldt select new { Name = String.Format("{0:dd MMM, yyyy [dddd]}", dt), Value = dt }; return(new SelectList(list, "Value", "Name")); }
// GET: ConsularAppt/Details/5 public ActionResult Details(int id) { ConsularApptVM model = EmbassyAppDb.GetConsularApptById(id); AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(model.AppointmentType); ViewBag.AppointmentType = appointmentType.Description; return(View(model)); }
// GET: Admin/PrintApptLtr/5 public ActionResult PrintApptLtr(int id) { ConsularApptVM model = EmbassyAppDb.GetConsularApptById(id); AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(model.AppointmentType); string pdfTemplateFile = ConfirmationLetterPdf.GetPdfTemplateFileName(appointmentType, model.StayType); MemoryStream pdfStream = ConfirmationLetterPdf.GetAppointmentLetterStream(pdfTemplateFile, model); //string confirmationLetter = this.GetConfirmationLetter(id); //MemoryStream pdfStream = new MemoryStream(); //Pdf.WriteHtmlToPdfStream(confirmationLetter, pdfStream); return(new FileStreamResult(pdfStream, "application/pdf")); }
public ActionResult GetCSV(string ppNum, DateTime?apptDt) { List <ConsularApptVM> list = EmbassyAppDb.GetConsularApptsAdmin(ppNum, apptDt); if (list.Count <= 0) { return(new EmptyResult()); } string csvString = EmbassyAppDb.GetConsularApptsAdminCSV(list, ','); string csvFileName = String.Format("Appointments_{0}{1}.csv", apptDt == null ? "All" : apptDt.Value.ToString("yyyyMMdd"), string.IsNullOrEmpty(ppNum) ? string.Empty : ppNum); return(File(new System.Text.UTF8Encoding().GetBytes(csvString), "text/csv", csvFileName)); }
// GET: Admin public ActionResult Index(string passportNumber, DateTime?appointmentDate) { List <ConsularApptVM> list = EmbassyAppDb.GetConsularApptsAdmin(passportNumber, appointmentDate); if (list.Count > 0) { ViewBag.DownloadCsv = true; ViewBag.PassportNumber = passportNumber; ViewBag.AppointmentDate = appointmentDate; } else { ViewBag.DownloadCsv = false; } return(View(list)); }
public async Task <ActionResult> Create([Bind(Include = "AppointmentDate,AppointmentType,Name,Gender,DateOfBirth,PlaceOfBirth,Nationality,NRIC_No,PassportNumber,PassportIssuedDate,ConsulateLocation,StayType,StayPermitNumber,EmployerName,Occupation,ContactAddr1,ContactAddr2,ContactPhone,ContactEmail,HomeAddr1,HomeAddr2,HomePhone,Note")] ConsularApptVM consularApptVM) { if (!Request.IsAuthenticated) { ViewBag.Title = "Embassy Consular Appointment Form"; EmbassyAppDb.AddConsularAppt(consularApptVM, EmWebAppConfig.QueueNumberInitial); Email email = this.GetConfirmationRequestEmail(consularApptVM); using (var smtp = new SmtpClient()) { smtp.Prep(); await smtp.SendMailAsync(email.Message); } ViewBag.PartialHtml = "_MsgApptReceived"; } else { ViewBag.Title = "Embassy Consular Appointment Form (Admin)"; consularApptVM.Note = "[ADMIN]" + consularApptVM.Note; EmbassyAppDb.AddConsularAppt(consularApptVM, EmWebAppConfig.QueueNumberInitial); DateTime? confirmedApptDate = null; int? confirmedQueNumber = 0; ConsularApptVM consularApptVM2 = EmbassyAppDb.ConfirmConsularAppt(consularApptVM.Id, consularApptVM.ActivationCode, ref confirmedApptDate, ref confirmedQueNumber); consularApptVM.QueueNumber = confirmedQueNumber.GetValueOrDefault(); ViewBag.PartialHtml = "_MsgApptConfirmedByAdmin"; } AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(consularApptVM.AppointmentType); ViewBag.AppointmentType = appointmentType.Description; return(View(consularApptVM)); }
public async Task <ActionResult> ConfirmPosted(string confirmedId, string confirmedCode) { if (!Request.IsAjaxRequest()) { return(Content("Request Error.")); } int id = int.Parse(confirmedId); string code = confirmedCode; DateTime? confirmedApptDate = null; int? confirmedQueNumber = 0; ConsularApptVM consularApptVM = EmbassyAppDb.ConfirmConsularAppt(id, code, ref confirmedApptDate, ref confirmedQueNumber); if (consularApptVM == null) { return(RedirectToAction("Error")); } string confirmedEmailBody = this.GetConfirmedEmailBody(consularApptVM); string confirmationLetter = this.GetConfirmationLetter(consularApptVM); // To do: Maybe convert the confirmationLetter to PDF, or get fillable PDF letter // Get Required Form Attachment List AppointmentType appointmentType = ConsularAppointmentTypes.GetAppointmentType(consularApptVM.AppointmentType); List <BLL.Attachment> formAttachments = appointmentType.Attachments?.List; // Start preparing for Email Email embassyMail = new Email { From = EmWebAppConfig.EmailAddress, DisplayName = EmWebAppConfig.EmailUser, To = consularApptVM.ContactEmail, Subject = EmWebAppConfig.EmailSubj_Confirmed, Body = confirmedEmailBody, IsHtml = true }; // using (MemoryStream ms = new MemoryStream()) string pdfTemplateFile = ConfirmationLetterPdf.GetPdfTemplateFileName(appointmentType, consularApptVM.StayType); using (MemoryStream ms = ConfirmationLetterPdf.GetAppointmentLetterStream(pdfTemplateFile, consularApptVM)) using (MailMessage mailMsg = embassyMail.Message) using (var smtp = new SmtpClient()) { System.Net.Mail.Attachment coverLetterPdf = Email.GetPdfAttachmentFromPdfStream(ms, "AppointmentLetter.pdf"); // System.Net.Mail.Attachment coverLetterPdf = Email.GetPdfAttachmentFromHtmlString(confirmationLetter, ms, "AppointmentLetter.pdf"); mailMsg.Attachments.Add(coverLetterPdf); if (formAttachments != null) { foreach (var attachment in formAttachments) { if (System.IO.File.Exists(attachment.FullPath)) { var emailAttachment = new System.Net.Mail.Attachment(attachment.FullPath, new ContentType(MediaTypeNames.Application.Pdf)); mailMsg.Attachments.Add(emailAttachment); } } } smtp.Prep(); await smtp.SendMailAsync(mailMsg); // return View(consularApptVM); return(PartialView("_MsgApptConfirmed", consularApptVM)); } }