Exemple #1
0
        //public FileStreamResult GetFileFromDisk(int valueId)
        //{
        //    FileValueObject obj = _formRepo.GetFileFieldValue(valueId);
        //    if (obj != null)
        //    {
        //        if (obj.IsSavedInCloud)
        //        {

        //        }
        //        else
        //        {
        //            var filePath = Server.MapPath(obj.SavePath.ConcatWith("/", obj.SaveName));
        //            var stream = UtilityHelper.ReadFile(filePath);
        //            return File(stream, System.Net.Mime.MediaTypeNames.Application.Octet, obj.FileName);
        //        }
        //    }

        //    throw new Exception("File Not Found");
        //}

        public ActionResult ViewSaveForm(int id, string entryId, bool embed = false)
        {
            using (var formManager = new FormAccessManager(GetLoginUser()))
            {
                TemplateViewModel model = null;

                var template = formManager.FindLatestTemplate(id);

                if (template != null)
                {
                    model       = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);
                    model.Embed = embed;
                }
                else
                {
                    return(RedirectToError("invalid id"));
                }

                foreach (var field in model.Fields)
                {
                    field.EntryId = entryId;
                }

                return(View("FillIn", model));
            }
        }
Exemple #2
0
        public ActionResult FillIn(int id, bool embed = false)
        {
            using (var formManager = new FormAccessManager(GetLoginUser()))
            {
                TemplateViewModel model = null;

                var template = formManager.FindTemplate(id);

                if (template != null)
                {
                    model = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);

                    if (!model.IsPublic && !IsUserAuthenticated())
                    {
                        return(RedirectToError("Unauthorized access"));
                    }

                    model.Embed = embed;
                }
                else
                {
                    return(RedirectToError("invalid id"));
                }

                return(View(model));
            }
        }
Exemple #3
0
        public string DeleteTemplate(int templateID)
        {
            string result = null;

            using (var unitOfWork = CreateUnitOfWork())
            {
                var template = FindTemplate(templateID);

                if (template != null)
                {
                    var templateView = TemplateViewModel.CreateFromObject(template);

                    var templates = FindAllTemplatesByFormId(template.FormID);
                    if (templates.Count() == 1)
                    {
                        result = "Unable to delete template when there is only one remains";
                    }

                    else
                    {
                        templateView.Entries = HasSubmissions(templateView).ToList();

                        if (!templateView.Entries.Any())
                        {
                            try
                            {
                                using (TransactionScope scope = new TransactionScope())
                                {
                                    unitOfWork.FormRepository.DeleteTemplate(templateID);

                                    unitOfWork.Complete();
                                    scope.Complete();

                                    result = "success";
                                }
                            }
                            catch
                            {
                                result = "Unable to delete template - there is an error deleting the template";
                            }
                        }

                        else
                        {
                            result = "Unable to delete template - Template must have no entries to be able to be deleted";
                        }
                    }
                }

                else
                {
                    result = "Unable to delete template - invalid id";
                }
            }

            return(result);
        }
        public ActionResult InternalFillIn(IDictionary <string, string> SubmitFields, TemplateViewModel model, FormCollection formCollection)
        {
            InsertValuesIntoTempData(formCollection);

            using (var participantJourneyManager = new ParticipantJourneyManager(GetLoginUser()))
            {
                var template = participantJourneyManager.FindTemplate(model.TemplateID.Value);

                var templateView = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);

                string nric       = null;
                string eventId    = null;
                int    modalityId = -1;
                if (TempData.Peek("SelectedModalityId") != null)
                {
                    modalityId = (int)TempData.Peek("SelectedModalityId");
                }

                ParticipantJourneySearchViewModel psm = (ParticipantJourneySearchViewModel)TempData.Peek("ParticipantJourneySearchViewModel");

                if (psm != null)
                {
                    eventId = psm.PHSEventId.ToString();
                    nric    = psm.Nric;
                }

                string result = participantJourneyManager.InternalFillIn(psm, modalityId, SubmitFields, model, formCollection);

                if (result.Equals("success"))
                {
                    List <ParticipantJourneyModalityCircleViewModel> participantJourneyModalityCircles = (List <ParticipantJourneyModalityCircleViewModel>)TempData.Peek("ParticipantJourneyModalityCircleViewModel");

                    foreach (var participantJourneyModalityCircle in participantJourneyModalityCircles)
                    {
                        if (participantJourneyModalityCircle.isModalityFormsContain(templateView.FormID))
                        {
                            participantJourneyModalityCircle.modalityCompletedForms.Add(templateView.FormID);
                        }
                    }

                    RemoveValuesFromTempData(formCollection);

                    TempData["ParticipantJourneyModalityCircleViewModel"] = participantJourneyModalityCircles;
                    //TempData["success"] = templateView.ConfirmationMessage;
                    return(Json(new { success = true, message = "Your changes were saved.", isautosave = false }));
                }

                else
                {
                    //TempData["error"] = result;
                    return(Json(new { success = false, error = result, isautosave = false }));
                }
            }
        }
Exemple #5
0
        public ActionResult SubmitConfirmation(int id, bool?embed)
        {
            using (var formManager = new FormAccessManager(GetLoginUser()))
            {
                var template = formManager.FindTemplate(id);
                if (template != null)
                {
                    var templateView = TemplateViewModel.CreateFromObject(template);
                    templateView.Embed  = embed ?? embed.Value;
                    TempData["success"] = templateView.ConfirmationMessage;
                    return(View(templateView));
                }

                return(RedirectToError("invalid id"));
            }
        }
Exemple #6
0
        public TemplateViewModel FindTemplateToEdit(int templateID)
        {
            using (var unitOfWork = CreateUnitOfWork())
            {
                Template template = unitOfWork.FormRepository.GetTemplate(templateID);

                if (template == null)
                {
                    return(null);
                }

                Constants.TemplateMode Mode = Constants.TemplateMode.EDIT;

                var templateView = TemplateViewModel.CreateFromObject(template);
                templateView.Entries = HasSubmissions(templateView).ToList();

                if (templateView.Entries.Any())
                {
                    var templates = FindAllTemplatesByFormId(template.FormID);
                    if (templates.Count() == template.Version)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            IDictionary <int, TemplateField> conditionFields = new System.Collections.Generic.Dictionary <int, TemplateField>();
                            template = unitOfWork.FormRepository.CopyTemplate(template, out conditionFields);

                            unitOfWork.Complete();

                            template = unitOfWork.FormRepository.CopyConditionFields(template, conditionFields);

                            unitOfWork.Complete();
                            scope.Complete();
                        }
                    }

                    else
                    {
                        Mode = Constants.TemplateMode.READONLY;
                    }
                }

                TemplateViewModel model1 = TemplateViewModel.CreateFromObject(template);
                model1.Mode = Mode;

                return(model1);
            }
        }
Exemple #7
0
        public TemplateViewModel FindTemplateToDisplay(ParticipantJourneySearchViewModel psm, int formID, int selectedModalityId, bool embed, TemplateFieldMode fieldMode, out string message)
        {
            TemplateViewModel model = null;

            using (var unitOfWork = CreateUnitOfWork())
            {
                ParticipantJourneyModality participantJourneyModality = RetrieveParticipantJourneyModality(psm, formID, selectedModalityId, out message);

                if (participantJourneyModality != null)
                {
                    var template = participantJourneyModality.TemplateID.HasValue ? unitOfWork.FormRepository.GetTemplate(participantJourneyModality.TemplateID.Value) : FindLatestTemplate(formID, unitOfWork);

                    if (template != null)
                    {
                        model       = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);
                        model.Embed = embed;

                        bool valueRequiredForRegistration = false;

                        if (Internal_Form_Type_Registration.Equals(model.InternalFormType))
                        {
                            if (participantJourneyModality.EntryId == Guid.Empty)
                            {
                                valueRequiredForRegistration = true;
                            }
                        }

                        foreach (var field in model.Fields)
                        {
                            field.Mode            = fieldMode;
                            field.ParticipantNric = psm.Nric;
                            field.IsValueRequiredForRegistration = valueRequiredForRegistration;
                            field.EntryId = participantJourneyModality.EntryId.ToString();
                        }
                    }
                }

                else
                {
                    throw new Exception("No participantJourneyModality found");
                }

                return(model);
            }
        }
Exemple #8
0
        //[SSl]
        public ActionResult PublicFillIn(string slug, bool embed = false)
        {
            using (var formManager = new FormAccessManager(GetLoginUser()))
            {
                var template = formManager.FindPublicTemplate(slug);

                if (template != null)
                {
                    TemplateViewModel model = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);
                    model.Embed = embed;
                    return(View(model));
                }
                else
                {
                    throw new HttpException(404, "No public Form found");
                }
            }
        }
Exemple #9
0
        public ActionResult FillIn(IDictionary <string, string> SubmitFields, TemplateViewModel model, FormCollection formCollection)
        {
            InsertValuesIntoTempData(SubmitFields, formCollection);

            using (var formManager = new FormAccessManager(GetLoginUser()))
            {
                var template = formManager.FindTemplate(model.TemplateID.Value);

                var    templateView = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);
                string result       = formManager.FillIn(SubmitFields, model, formCollection);

                if (result.Equals("success"))
                {
                    //send notification
                    if (!templateView.NotificationEmail.IsNullOrEmpty() && WebConfig.Get <bool>("enablenotifications", true))
                    {
                        var notificationView = new NotificationEmailViewModel();
                        notificationView.FormName = templateView.Title;
                        notificationView.Email    = templateView.NotificationEmail;

                        //TODO if need to use this, need to retrieve the entries
                        //notificationView.Entries = ??;

                        NotifyViaEmail(notificationView);
                    }

                    RemoveValuesFromTempData(formCollection);

                    TempData["success"] = templateView.ConfirmationMessage;
                    return(RedirectToRoute("form-submitconfirmation", new
                    {
                        id = template.TemplateID,
                        embed = model.Embed
                    }));
                }

                else
                {
                    TempData["error"] = result;
                    return(View("FillIn", templateView));
                }
            }
        }
Exemple #10
0
        public ActionResult PreRegistration()
        {
            using (var formManager = new FormAccessManager(GetLoginUser()))
            {
                TemplateViewModel model = null;

                var template = formManager.FindPreRegistrationForm();

                if (template != null)
                {
                    model = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);
                }
                else
                {
                    throw new HttpException(404, "No Pre Registration Form found");
                }

                return(View("PreRegistration", model));
            }
        }
Exemple #11
0
        public ActionResult PreviewTemplate(int id)
        {
            if (!IsUserAuthenticated())
            {
                //TODO - View Form Authentication
                // return RedirectToLogin();
            }

            using (var formManager = new FormManager())
            {
                Template template = formManager.FindTemplate(id);

                if (template != null)
                {
                    TemplateViewModel model = TemplateViewModel.CreateFromObject(template, Constants.TemplateFieldMode.INPUT);
                    return(View(model));
                }
                else
                {
                    return(RedirectToError("invalid id"));
                }
            }
        }
Exemple #12
0
        public string FillIn(IDictionary <string, string> SubmitFields, Template Template, FormCollection formCollection)
        {
            string         result = null;
            IList <string> errors = Enumerable.Empty <string>().ToList();

            var templateView = TemplateViewModel.CreateFromObject(Template, Constants.TemplateFieldMode.INPUT);

            templateView.AssignInputValues(formCollection);

            if (templateView.Fields.Any())
            {
                IDictionary <int, string> submissionFields = new System.Collections.Generic.Dictionary <int, string>();

                // first validate fields
                foreach (var field in templateView.Fields.OrderBy(f => f.TemplateFieldID))
                {
                    if (!field.SubmittedValueIsValid(formCollection))
                    {
                        field.SetFieldErrors();
                        errors.Add(field.Errors);
                    }

                    var value = field.SubmittedValue(formCollection);
                    if (field.IsRequired && value.IsNullOrEmpty())
                    {
                        if (field.ConditionTemplateFieldID.HasValue)
                        {
                            if (isConditionalFieldRequired(field, submissionFields))
                            {
                                field.Errors = "{0} is a required field".FormatWith(field.Label);
                                errors.Add(field.Errors);
                            }

                            else
                            {
                                submissionFields.Add(field.TemplateFieldID.Value, value);
                            }
                        }

                        else
                        {
                            field.Errors = "{0} is a required field".FormatWith(field.Label);
                            errors.Add(field.Errors);
                        }
                    }

                    else
                    {
                        submissionFields.Add(field.TemplateFieldID.Value, value);
                    }
                }
                ;

                if (errors.Count == 0)
                {
                    //then insert values
                    var entryId = Guid.NewGuid();

                    using (TransactionScope scope = new TransactionScope())
                    {
                        foreach (var field in templateView.Fields.OrderBy(f => f.TemplateFieldID))
                        {
                            if (field.ConditionTemplateFieldID.HasValue)
                            {
                                if (isConditionalFieldRequired(field, submissionFields))
                                {
                                    var value = field.SubmittedValue(formCollection);

                                    HandleTemplateFieldValue(field, value, entryId);
                                }
                            }

                            else
                            {
                                var value = field.SubmittedValue(formCollection);

                                HandleTemplateFieldValue(field, value, entryId);
                            }
                        }

                        HandleAdditionalInsert(templateView, Template, formCollection, entryId, submissionFields);

                        UnitOfWork.Complete();
                        scope.Complete();

                        result = "success";
                    }
                }
            }

            if (errors.Count > 0)
            {
                result = errors.ToUnorderedList();
            }


            return(result);
        }