public void RetrieveParticipantJourney_NotActiveEvent() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; PHSEvent phsEvent = new PHSEvent() { Title = "Test", Venue = "Test", StartDT = DateTime.Now.AddDays(-2), EndDT = DateTime.Now.AddDays(-1), IsActive = false }; _unitOfWork.Events.Add(phsEvent); _unitOfWork.Complete(); string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel result = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNull(result); Assert.AreEqual("Screening Event is not active", message); }
public void RetrieveParticipantJourney_NoParticipantMessage() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; PHSEvent phsEvent = new PHSEvent() { Title = "Test", Venue = "Test", StartDT = DateTime.Now.AddDays(-2), EndDT = DateTime.Now.AddDays(1), IsActive = true }; _unitOfWork.Events.Add(phsEvent); _unitOfWork.Complete(); string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel result = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNull(result); Assert.AreEqual("No registration record found. Do you want to register this Nric?", message); }
public ActionResult RefreshViewParticipantJourneyParticipant() { ParticipantJourneySearchViewModel psm = (ParticipantJourneySearchViewModel)TempData.Peek("ParticipantJourneySearchViewModel"); if (psm == null) { return(Redirect("Index")); } using (var participantJourneyManager = new ParticipantJourneyManager()) { string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel result = participantJourneyManager.RetrieveParticipantJourney(psm, out message, out messageType); if (result == null) { SetViewBagError(message); return(Redirect("Index")); } return(PartialView("_ViewParticipantJourneyParticipantPartial", result)); } }
public List <ParticipantJourneyModalityCircleViewModel> GetParticipantMegaSortingStation(ParticipantJourneySearchViewModel psm) { using (var unitOfWork = CreateUnitOfWork()) { PHSEvent phsEvent = unitOfWork.Events.Get(psm.PHSEventId); Participant participant = unitOfWork.Participants.FindParticipant(psm.Nric, phsEvent.PHSEventID); IEnumerable <ParticipantJourneyModality> ptJourneyModalityItems = unitOfWork.ParticipantJourneyModalities.GetParticipantJourneyModalityByParticipantEvent(psm.Nric, phsEvent.PHSEventID); ParticipantJourneyViewModel pjvm = new ParticipantJourneyViewModel(participant, psm.PHSEventId); List <ParticipantJourneyModalityCircleViewModel> pjmCircles = new List <ParticipantJourneyModalityCircleViewModel>(); foreach (Modality modality in phsEvent.Modalities) { IList <ParticipantJourneyModality> matchedPjms = new List <ParticipantJourneyModality>(); foreach (ParticipantJourneyModality pjm in ptJourneyModalityItems) { if (modality.ModalityID == pjm.Modality.ModalityID && pjm.PHSEvent.Equals(phsEvent)) { matchedPjms.Add(pjm); modality.IsActive = true; } } if (modality.IsVisible && modality.Status != "Public") { pjmCircles.Add(copyToPJMCVM(pjvm, modality, matchedPjms)); } } return(pjmCircles); } }
public ActionResult SearchParticipantJourney(ParticipantJourneySearchViewModel psm) { if (psm == null) { return(View()); } using (var participantJourneyManager = new ParticipantJourneyManager()) { string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel result = participantJourneyManager.RetrieveParticipantJourney(psm, out message, out messageType); if (result == null) { if (MessageType.ERROR == messageType) { SetViewBagError(message); } else { SetViewBagMessage(message); } TempData["ToRegister"] = psm; if (Request.IsAjaxRequest()) { return(PartialView("_SearchParticipantJourneyResultPartial", psm)); } else { return(View(psm)); } } else { string url = Url.Action("ViewParticipantJourney", "ParticipantJourney", new { Nric = psm.Nric, PHSEventId = psm.PHSEventId }); return(JavaScript("window.location = '" + url + "'")); } } }
public ActionResult ViewPastParticipantJourney(string Nric, int PHSEventId) { if (string.IsNullOrEmpty(Nric) || PHSEventId == 0) { return(Redirect("Index")); } ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel() { Nric = Nric, PHSEventId = PHSEventId }; using (var participantJourneyManager = new PastParticipantJourneyManager(GetLoginUser())) { string message = string.Empty; ParticipantJourneyViewModel result = participantJourneyManager.RetrievePastParticipantJourney(psm, out message); if (!string.IsNullOrEmpty(message)) { SetViewBagError(message); return(Redirect("Index")); } else { List <ParticipantJourneyModalityCircleViewModel> participantJourneyModalityCircles = participantJourneyManager.GetParticipantMegaSortingStation(psm); ParticipantJourneyFormViewModel participantJourneyformView = new ParticipantJourneyFormViewModel(result.Participant, psm.PHSEventId); participantJourneyformView.SelectedModalityId = result.Event.Modalities.First().ModalityID; TempData["ParticipantJourneySearchViewModel"] = psm; TempData["ParticipantJourneyModalityCircleViewModel"] = participantJourneyModalityCircles; TempData["ParticipantJourneyFormViewModel"] = participantJourneyformView; TempData["SelectedModalityId"] = participantJourneyformView.SelectedModalityId; TempData["ViewParticipantJourneyType"] = Constants.TemplateFieldMode.READONLY; return(View("~/Views/ParticipantJourney/ViewParticipantJourney.cshtml", result)); } } }
public void RetrieveParticipantJourney_FoundParticipant() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; PHSEvent phsEvent = new PHSEvent() { Title = "Test", Venue = "Test", StartDT = DateTime.Now.AddDays(-2), EndDT = DateTime.Now.AddDays(1), IsActive = true }; Participant participant = new Participant() { Nric = "S8250369B", DateOfBirth = DateTime.Now }; _unitOfWork.Events.Add(phsEvent); participant.PHSEvents.Add(phsEvent); _unitOfWork.Participants.Add(participant); _unitOfWork.Complete(); string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel result = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.AreEqual(string.Empty, message); Assert.IsNotNull(result); Assert.IsNotNull(result.Event); Assert.AreEqual(phsEvent.PHSEventID, result.Event.PHSEventID); }
public ActionResult ViewParticipantJourney(ParticipantJourneySearchViewModel psm) { if (psm == null) { return(Redirect("Index")); } using (var participantJourneyManager = new ParticipantJourneyManager(GetLoginUser())) { string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel result = participantJourneyManager.RetrieveParticipantJourney(psm, out message, out messageType); if (result == null) { SetViewBagError(message); return(Redirect("Index")); } else { List <ParticipantJourneyModalityCircleViewModel> participantJourneyModalityCircles = participantJourneyManager.GetParticipantMegaSortingStation(psm); ParticipantJourneyFormViewModel participantJourneyformView = new ParticipantJourneyFormViewModel(result.Participant, psm.PHSEventId); participantJourneyformView.SelectedModalityId = result.Event.Modalities.First().ModalityID; TempData["ParticipantJourneySearchViewModel"] = psm; TempData["ParticipantJourneyModalityCircleViewModel"] = participantJourneyModalityCircles; TempData["ParticipantJourneyFormViewModel"] = participantJourneyformView; TempData["SelectedModalityId"] = participantJourneyformView.SelectedModalityId; TempData["ViewParticipantJourneyType"] = Constants.TemplateFieldMode.INPUT; return(View(result)); } } }
public ParticipantJourneyViewModel RetrievePastParticipantJourney(ParticipantJourneySearchViewModel psm, out string message) { message = string.Empty; ParticipantJourneyViewModel result = null; if (psm == null) { message = "Parameter cannot be null"; } else if (string.IsNullOrEmpty(psm.Nric) || psm.PHSEventId == 0) { message = "Please enter valid NRIC and select an Event"; } else { using (var unitOfWork = CreateUnitOfWork()) { Participant participant = unitOfWork.Participants.FindParticipant(psm.Nric, psm.PHSEventId); if (participant != null) { result = new ParticipantJourneyViewModel(participant, psm.PHSEventId); } else { message = "No result found"; } } } return(result); }
public void RegisterParticipant_ExistingParticipantAndPHSEventWithPreRegistration() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 2; PHSEvent phsEventOne = new PHSEvent() { Title = "Test 15", Venue = "Test", StartDT = DateTime.Now.AddDays(-200), EndDT = DateTime.Now.AddDays(-199), IsActive = false }; PHSEvent phsEventTwo = new PHSEvent() { Title = "Test 16", Venue = "Test", StartDT = DateTime.Now.AddDays(-2), EndDT = DateTime.Now.AddDays(1), IsActive = true }; Participant participant = new Participant() { Nric = "S8250369B", DateOfBirth = DateTime.Now, HomeNumber = "88776655" }; PreRegistration preRegistration = new PreRegistration() { Nric = "S8250369B", Address = "Test Add", Citizenship = "Singaporean", HomeNumber = "12345678", FullName = "Tester", Gender = "Male", Salutation = "Mr", Race = "Chinese", Language = "English", DateOfBirth = DateTime.Now, EntryId = Guid.NewGuid() }; Modality modality = new Modality() { Name = "Test Modality", IsMandatory = true }; Form form = new Form { Title = "Test form" }; _unitOfWork.PreRegistrations.Add(preRegistration); _unitOfWork.Events.Add(phsEventOne); _unitOfWork.Events.Add(phsEventTwo); participant.PHSEvents.Add(phsEventOne); _unitOfWork.Participants.Add(participant); modality.Forms.Add(form); phsEventTwo.Modalities.Add(modality); _unitOfWork.Complete(); string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel preResult = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNull(preResult); string registerResult = _target.RegisterParticipant(psm); Assert.AreEqual("success", registerResult); ParticipantJourneyViewModel postResult = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNotNull(postResult); Assert.IsNotNull(postResult.Event); Assert.AreEqual("12345678", postResult.HomeNumber); var pjmResult = _unitOfWork.ParticipantJourneyModalities.Find(u => u.PHSEventID == postResult.Event.PHSEventID).FirstOrDefault(); Assert.IsNotNull(pjmResult); Assert.AreEqual(1, pjmResult.ParticipantID); Assert.AreEqual(1, pjmResult.ModalityID); Assert.AreEqual(2, pjmResult.PHSEventID); Assert.AreEqual(1, pjmResult.FormID); }
public void RegisterParticipant_ExistingParticipantAndPHSEvent() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 2; PHSEvent phsEventOne = new PHSEvent() { Title = "Test 15", Venue = "Test", StartDT = DateTime.Now.AddDays(-200), EndDT = DateTime.Now.AddDays(-199), IsActive = false }; PHSEvent phsEventTwo = new PHSEvent() { Title = "Test 16", Venue = "Test", StartDT = DateTime.Now.AddDays(-2), EndDT = DateTime.Now.AddDays(1), IsActive = true }; Participant participant = new Participant() { Nric = "S8250369B", DateOfBirth = DateTime.Now, HomeNumber = "88776655" }; Modality modality = new Modality() { Name = "Test Modality", IsMandatory = true }; Form form = new Form { Title = "Test form" }; _unitOfWork.Events.Add(phsEventOne); _unitOfWork.Events.Add(phsEventTwo); participant.PHSEvents.Add(phsEventOne); _unitOfWork.Participants.Add(participant); modality.Forms.Add(form); phsEventTwo.Modalities.Add(modality); _unitOfWork.Complete(); string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel preResult = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNull(preResult); string registerResult = _target.RegisterParticipant(psm); Assert.AreEqual("success", registerResult); ParticipantJourneyViewModel postResult = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNotNull(postResult); Assert.IsNotNull(postResult.Event); Assert.AreEqual("88776655", postResult.HomeNumber); var pjmResult = _unitOfWork.ParticipantJourneyModalities.Find(u => u.PHSEventID == postResult.Event.PHSEventID).FirstOrDefault(); Assert.IsNotNull(pjmResult); Assert.AreEqual(1, pjmResult.ParticipantID); Assert.AreEqual(1, pjmResult.ModalityID); Assert.AreEqual(2, pjmResult.PHSEventID); Assert.AreEqual(1, pjmResult.FormID); }
public void RegisterParticipant_ParticipantJourneyModalityCreatedBasedOnMandatoryModality() { ParticipantJourneySearchViewModel psm = new ParticipantJourneySearchViewModel(); psm.Nric = "S8250369B"; psm.PHSEventId = 1; PHSEvent phsEvent = new PHSEvent() { Title = "Test", Venue = "Test", StartDT = DateTime.Now.AddDays(-1), EndDT = DateTime.Now.AddDays(1), IsActive = true }; Modality modalityOne = new Modality() { Name = "Test Reg", IsMandatory = true }; Modality modalityTwo = new Modality() { Name = "Test Modality", IsMandatory = false }; Form formOne = new Form { Title = "Test reg form" }; Form formTwo = new Form { Title = "Test form" }; modalityOne.Forms.Add(formOne); modalityTwo.Forms.Add(formTwo); phsEvent.Modalities.Add(modalityOne); phsEvent.Modalities.Add(modalityTwo); _unitOfWork.Events.Add(phsEvent); _unitOfWork.Complete(); string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel preResult = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNull(preResult); string registerResult = _target.RegisterParticipant(psm); Assert.AreEqual("success", registerResult); ParticipantJourneyViewModel postResult = _target.RetrieveParticipantJourney(psm, out message, out messageType); Assert.IsNotNull(postResult); Assert.IsNotNull(postResult.Event); Assert.IsNull(postResult.Gender); var pjmResult = _unitOfWork.ParticipantJourneyModalities.Find(u => u.PHSEventID == postResult.Event.PHSEventID).FirstOrDefault(); Assert.IsNotNull(pjmResult); Assert.AreEqual(1, pjmResult.ParticipantID); Assert.AreEqual(1, pjmResult.ModalityID); Assert.AreEqual(1, pjmResult.PHSEventID); Assert.AreEqual(1, pjmResult.FormID); IEnumerable <ParticipantJourneyModality> particpantJourneyModalities = _unitOfWork.ParticipantJourneyModalities.GetParticipantJourneyModalityByParticipantEvent("S8250369B", 1); Assert.AreEqual(1, particpantJourneyModalities.Count()); Assert.AreEqual("Test Reg", particpantJourneyModalities.FirstOrDefault().Modality.Name); }
public ActionResult GenerateLabel() { string templatePath = Server.MapPath("~/App_Data/Label.docx"); // Load template into memory var doc = DocX.Load(templatePath); ParticipantJourneySearchViewModel psm = (ParticipantJourneySearchViewModel)TempData.Peek("ParticipantJourneySearchViewModel"); using (var participantJourneyManager = new ParticipantJourneyManager()) { string message = string.Empty; MessageType messageType = MessageType.ERROR; ParticipantJourneyViewModel result = participantJourneyManager.RetrieveParticipantJourney(psm, out message, out messageType); doc.ReplaceText("<<EVENT>>", result.Event.Title + " " + result.Event.Venue); doc.ReplaceText("<<CURRENT_DATE>>", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); doc.ReplaceText("<<NAME>>", UtilityHelper.GetString(result.FullName).Limit(35)); doc.ReplaceText("<<NRIC>>", UtilityHelper.GetString(result.Nric)); doc.ReplaceText("<<GENDER>>", UtilityHelper.GetString(result.Gender)); doc.ReplaceText("<<DOB>>", UtilityHelper.GetString(result.DateOfBirth)); doc.ReplaceText("<<RACE>>", UtilityHelper.GetString(result.Race).Limit(8)); doc.ReplaceText("<<HOME>>", UtilityHelper.GetString(result.HomeNumber).Limit(8)); doc.ReplaceText("<<HP>>", UtilityHelper.GetString(result.MobileNumber).Limit(8)); doc.ReplaceText("<<ADD>>", UtilityHelper.GetString(result.GetAddressWithoutPrefix()).Limit(48)); //doc.ReplaceText("<<UNIT>>", result.un); doc.ReplaceText("<<POSTAL>>", UtilityHelper.GetString(result.PostalCode)); doc.ReplaceText("<<LANG>>", UtilityHelper.GetString(result.Language).Limit(8)); var ms = new MemoryStream(); doc.SaveAs(ms); ms.Position = 0; byte[] fileBytes = ms.ToArray(); String guid = Guid.NewGuid().ToString(); TempData[guid] = fileBytes; /* * return new JsonResult() * { * Data = new { FileGuid = guid, FileName = psm.Nric + ".docx" } * }; */ Document docTest = new Document(); docTest.LoadFromStream(ms, FileFormat.Docx); MemoryStream stream = new MemoryStream(); docTest.SaveToStream(stream, FileFormat.PDF); stream.Flush(); //Always catches me out stream.Position = 0; //Not sure if this is required TempData[guid] = stream.ToArray(); return(new JsonResult() { Data = new { FileGuid = guid, FileName = psm.Nric + ".pdf" } }); /* * //return File(stream, "application/pdf"); * Response.AppendHeader("Content-Disposition", "inline; filename=name.pdf"); * return new FileContentResult(stream.ToArray(), "application/pdf"); */ } }
public ParticipantJourneyViewModel RetrieveParticipantJourney(ParticipantJourneySearchViewModel psm, out string message, out MessageType messageType) { message = string.Empty; messageType = MessageType.ERROR; ParticipantJourneyViewModel result = null; if (psm == null) { message = "Parameter cannot be null"; } else if (string.IsNullOrEmpty(psm.Nric) || psm.PHSEventId == 0) { message = "Please enter valid NRIC and select Live Event"; } else if (!NricChecker.IsNRICValid(psm.Nric)) { message = "Invalid Nric"; } else { using (var unitOfWork = CreateUnitOfWork()) { PHSEvent phsEvent = unitOfWork.Events.GetAllActiveEvents().Where(e => e.PHSEventID == psm.PHSEventId).FirstOrDefault(); if (phsEvent == null) { message = "Screening Event is not active"; } else { Participant participant = unitOfWork.Participants.FindParticipant(psm.Nric, psm.PHSEventId); if (participant != null) { result = new ParticipantJourneyViewModel(participant, psm.PHSEventId); } else { messageType = MessageType.PROMPT; PreRegistration preRegistration = unitOfWork.PreRegistrations.FindPreRegistration(p => p.Nric.Equals(psm.Nric)); if (preRegistration == null) { message = "No registration record found. Do you want to register this Nric?"; } else { message = "Do you want to register this Nric?"; } } } } } return(result); }
private ParticipantJourneyModalityCircleViewModel copyToPJMCVM(ParticipantJourneyViewModel pjvm, Modality modality, IList <ParticipantJourneyModality> matchedPjms) { ParticipantJourneyModalityCircleViewModel pjmcvm = new ParticipantJourneyModalityCircleViewModel(pjvm, modality, matchedPjms, GetLoginUserRole()); return(pjmcvm); }