Exemplo n.º 1
0
        private void CopyPolicyAnswers(ContentItem src, ContentItem dest)
        {
            var srcPolicy  = src.As <UserPolicyPart>();
            var destPolicy = dest.As <UserPolicyPart>();

            if (srcPolicy != null && destPolicy != null)
            {
                IPolicyServices policyServices = null;
                _orchardServices.WorkContext.TryResolve <IPolicyServices>(out policyServices);
                if (policyServices != null)
                {
                    var policyList = new List <PolicyForUserViewModel>();
                    var srcAnswers = policyServices.GetPolicyAnswersForContent(srcPolicy.Id);
                    foreach (var policy in srcAnswers)
                    {
                        policyList.Add(new PolicyForUserViewModel {
                            PolicyTextId = policy.PolicyTextInfoPartRecord.Id,
                            Accepted     = policy.Accepted,
                            AnswerDate   = policy.AnswerDate,
                            UserId       = (policy.UserPartRecord == null) ? null : (int?)policy.UserPartRecord.Id
                        });
                    }
                    policyServices.PolicyForItemMassiveUpdate(policyList, dest);
                }
            }
        }
Exemplo n.º 2
0
        private IEnumerable <PolicyAnswer> TryFindPolicyAnswers(MailchimpSubscriptionPart part)
        {
            // Read Answers from the DB
            var answers = _policyService.GetPolicyAnswersForContent(part.Id).Select(x => new PolicyAnswer {
                PolicyTextId = x.PolicyTextInfoPartRecord.Id,
                Accepted     = x.Accepted
            }).ToList();

            // Adds Current answers if existing
            if (_controllerAccessor.Context != null && _controllerAccessor.Context.Controller.ViewBag.PolicyAnswers != null)
            {
                var currentAnswers = (List <PolicyAnswer>)_controllerAccessor.Context.Controller.ViewBag.PolicyAnswers;
                foreach (var answer in currentAnswers)   //Removes previous answers to same Policy
                {
                    answers.RemoveAll((match) => {
                        return(match.PolicyTextId == answer.PolicyTextId);
                    });
                }
                answers = answers.Union(currentAnswers).ToList(); //Merge new answers
            }
            return(answers);
        }