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 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 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));
                }
            }
        }
Example #4
0
        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");
                 */
            }
        }