Ejemplo n.º 1
0
        public dynamic Verify(string parameters)
        {
            string encyptKey = ConfigurationManager.AppSettings["EncyptKey"];

            if (string.IsNullOrEmpty(encyptKey))
            {
                throw new Exception("EncyptKey not found in App.config");
            }

            var dataJson  = EncryptHelper.Base64Decode(parameters);
            var jSettings = new JsonSerializerSettings
            {
                Formatting           = Formatting.Indented,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            jSettings.Converters.Add(new DefaultWrongFormatDeserialize());
            var viewModel = JsonConvert.DeserializeObject <RequestAssessmentPcsVo>(dataJson, jSettings);

            //if tabSelected == 1 , Disclose form
            if (viewModel.TabSelected == 1)
            {
                var checkDisclosureForm = CheckInValidDisclosureForm(viewModel.DisclosureFormVo);
                if (checkDisclosureForm.Count > 0)
                {
                    var result = new ObjectReturnVo();
                    result.Error = checkDisclosureForm;
                    result.Id    = viewModel.AssessmentPcsId;
                    return(result);
                }
            }
            //if tabSelected == 2 , PCST form
            else
            {
                TrackingCompleteInformation(viewModel);
                if (viewModel.CurrentSectionId == null)
                {
                    var checkMid = CheckMidDisclosureFormAndPcstForm(viewModel);
                    if (checkMid.Count > 0)
                    {
                        if (viewModel.MessageErrorTotal == null)
                        {
                            viewModel.MessageErrorTotal = new List <MessageErrorVo>();
                            viewModel.MessageErrorTotal.AddRange(checkMid);
                        }
                        else
                        {
                            viewModel.MessageErrorTotal.AddRange(checkMid);
                        }
                    }
                    var checkErrorExpedited = CheckErrorExpedited(viewModel);
                    if (checkErrorExpedited.Count > 0)
                    {
                        viewModel.MessageErrorTotal.AddRange(checkErrorExpedited);
                    }
                }


                if (viewModel.MessageErrorTotal != null && viewModel.MessageErrorTotal.Count > 0)
                {
                    var index = 0;
                    foreach (var item in viewModel.MessageErrorTotal)
                    {
                        index++;
                        item.Index = index;
                    }
                    var result = new ObjectReturnVo();
                    result.Error = viewModel.MessageErrorTotal;
                    result.Id    = viewModel.AssessmentPcsId;
                    return(result);
                }
            }

            var result1 = new ObjectReturnVo();

            result1.Id = viewModel.AssessmentPcsId;
            return(result1);
        }
Ejemplo n.º 2
0
        public dynamic Save(string parameters)
        {
            string encyptKey = ConfigurationManager.AppSettings["EncyptKey"];

            if (string.IsNullOrEmpty(encyptKey))
            {
                throw new Exception("EncyptKey not found in App.config");
            }

            var dataJson  = EncryptHelper.Base64Decode(parameters);
            var jSettings = new JsonSerializerSettings
            {
                Formatting           = Formatting.Indented,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            jSettings.Converters.Add(new DefaultWrongFormatDeserialize());
            var viewModel = JsonConvert.DeserializeObject <RequestAssessmentPcsVo>(dataJson, jSettings);

            TrackingCompleteInformation(viewModel);

            var listDisclodureError      = new List <MessageErrorVo>();
            var IsDisclosureFormComplete = true;
            var listError = new List <MessageErrorVo>();

            if (viewModel.IsSaveAll == true)
            {
                var checkDisclosureForm = CheckInValidDisclosureForm(viewModel.DisclosureFormVo);
                if (checkDisclosureForm.Count > 0)
                {
                    if (viewModel.MessageErrorTotal == null)
                    {
                        viewModel.MessageErrorTotal = new List <MessageErrorVo>();
                        viewModel.MessageErrorTotal.AddRange(checkDisclosureForm);
                    }
                    else
                    {
                        viewModel.MessageErrorTotal.AddRange(checkDisclosureForm);
                    }
                    listDisclodureError      = checkDisclosureForm;
                    IsDisclosureFormComplete = false;
                }
                var checkMid = CheckMidDisclosureFormAndPcstForm(viewModel);
                if (checkMid.Count > 0)
                {
                    if (viewModel.MessageErrorTotal == null)
                    {
                        viewModel.MessageErrorTotal = new List <MessageErrorVo>();
                        viewModel.MessageErrorTotal.AddRange(checkMid);
                    }
                    else
                    {
                        viewModel.MessageErrorTotal.AddRange(checkMid);
                    }
                }

                if (viewModel.MessageErrorTotal != null && viewModel.MessageErrorTotal.Count > 0)
                {
                    var index = 0;
                    foreach (var item in viewModel.MessageErrorTotal)
                    {
                        index++;
                        item.Index = index;
                    }
                    //var result = new ObjectReturnVo();
                    //result.Error = viewModel.MessageErrorTotal;
                    //result.Id = viewModel.AssessmentPcsId;
                    //return result;
                    listError = viewModel.MessageErrorTotal;
                }
            }

            var assessmentData = new AssessmentDataVo
            {
                Sections = viewModel.Sections,
                AssessmentSectionQuestions = viewModel.AssessmentSectionQuestions,
            };
            //GetContentHtml(viewModel, assessmentData);

            var encryptAssessmentData =
                EncryptHelper.Encrypt(JsonConvert.SerializeObject(assessmentData), encyptKey);

            //parse string to DateTime
            if (viewModel.DisclosureFormVo.Member != null)
            {
                viewModel.DisclosureFormVo.Member.Dob =
                    CaculatorHelper.TryParseDatTimeFromStr(viewModel.DisclosureFormVo.Member.DobStr);//.GetValueOrDefault();
                if (viewModel.DisclosureFormVo.Member.Signature == "_blank")
                {
                    viewModel.DisclosureFormVo.Member.Signature = null;
                }
            }
            viewModel.DisclosureFormVo.DateSigned =
                CaculatorHelper.TryParseDatTimeFromStr(viewModel.DisclosureFormVo.DateSignedStr);       //.GetValueOrDefault();
            viewModel.DisclosureFormVo.TheFollowingDate =
                CaculatorHelper.TryParseDatTimeFromStr(viewModel.DisclosureFormVo.TheFollowingDateStr); //.GetValueOrDefault();
            if (viewModel.DisclosureFormVo.Guardian != null && viewModel.DisclosureFormVo.Guardian.Signature == "_blank")
            {
                viewModel.DisclosureFormVo.Guardian.Signature = null;
            }
            if (viewModel.DisclosureFormVo.IsHasProviderAgency)
            {
                //set MPI == id
                if (viewModel.DisclosureFormVo.Providers != null && viewModel.DisclosureFormVo.Providers.Count > 0)
                {
                    foreach (var dt in viewModel.DisclosureFormVo.Providers)
                    {
                        if (dt.Id != null && dt.Id.GetValueOrDefault() > 0)
                        {
                            dt.Mpi = dt.Id.ToString();
                        }
                    }
                }
            }
            else
            {
                viewModel.DisclosureFormVo.Providers = new List <ProviderDisclosureFormViewModel>();
            }
            var encryptDisclosureFormData =
                EncryptHelper.Encrypt(JsonConvert.SerializeObject(viewModel.DisclosureFormVo), encyptKey);

            var encryptMid = EncryptHelper.Encrypt(JsonConvert.SerializeObject(GetMid(viewModel)), encyptKey);

            var extensionVm = new ExtensionAssessment
            {
                DisclosureFormIsComplete = IsDisclosureFormComplete,
                ErrorDisclosureForm      = listDisclodureError
            };

            var extensionStr = JsonConvert.SerializeObject(extensionVm);

            using (var context = new AssessmentContext())
            {
                //Update
                if (viewModel.AssessmentPcsId > 0)
                {
                    var assessment = context.Assessments.FirstOrDefault(o => o.Id == viewModel.AssessmentPcsId);
                    if (assessment != null)
                    {
                        assessment.FileName           = viewModel.AssessmentName;
                        assessment.ModifiedOn         = DateTime.Now;
                        assessment.AssessmentData     = encryptAssessmentData;
                        assessment.DisclosureFormData = encryptDisclosureFormData;
                        assessment.Mid       = encryptMid;
                        assessment.Extension = extensionStr;

                        context.Entry(assessment).State = EntityState.Modified;
                        context.SaveChanges();

                        var result = new ObjectReturnVo();
                        result.Id    = assessment.Id;
                        result.Error = listError.Count > 0 ? listError : null;
                        return(result);
                    }
                    else
                    {
                        var result = new ObjectReturnVo();
                        result.Error = new List <MessageErrorVo>
                        {
                            new MessageErrorVo
                            {
                                MessageError = "This record was delete."
                            }
                        };
                        result.Id = 0;

                        return(result);
                    }
                }
                //Add
                else
                {
                    var entity = new Assessment
                    {
                        FileName           = viewModel.AssessmentName,
                        FilePath           = "",
                        CreatedOn          = DateTime.Now,
                        ModifiedOn         = DateTime.Now,
                        AssessmentData     = encryptAssessmentData,
                        DisclosureFormData = encryptDisclosureFormData,
                        Mid       = encryptMid,
                        Extension = extensionStr
                    };
                    context.Entry(entity).State = EntityState.Added;
                    context.SaveChanges();

                    var result = new ObjectReturnVo();
                    result.Id    = entity.Id;
                    result.Error = listError;
                    return(result);
                }
            }
        }