Example #1
0
        public virtual ActionResult ChildCategoryAttributes([Bind(Prefix = "ThreadForm.AttributeValues")]  AttributeValueModel[] attributeValues, int attributeId)
        {
            var helper = new CategoryAttributeHelper();
            var categoryAttributeValues = helper.GetCategoryAttributeValues(attributeValues != null ? attributeValues.Where(cv => cv.AttributeId == attributeId) : new AttributeValueModel[0]);
            var allSubAttributes = categoryAttributeValues.SelectMany(cav => cav.Attribute.ChildAttributes);
            var selectedSubAttributes = allSubAttributes.Where(sa => categoryAttributeValues.Any(cav => cav.SelectedOptions.Intersect(sa.ParentOptions).Any()));

            var model = new CategoryAttributesThreadFormModel
                            {
                                CategoryAttributes = selectedSubAttributes.ToList(),
                                CategoryAttributeValues = attributeValues
                            };

            return PartialView(MVC.Thread.Views._CategoryAttributes, model);
        }
Example #2
0
        public virtual ActionResult CategoryAttributes([Bind(Prefix = "ThreadForm")] ThreadForm form, int? brokerId)
        {
            if (brokerId != null)
                BrokerHelper.SetBrokerCookie(brokerId.Value);

            if (!ModelState.IsValid)
            {
                Log.Info(GetType(), "form-action:Form invalid");
                if (!ModelState.IsValidField("ThreadForm.CategoryId"))
                    Flash.Error("Wybierz kategoriÄ™ pytania");

                return View(MVC.StaticPages.Views.Home,
                            new HomeModel(Repository.Category.All()) {ThreadForm = form});
            }

            Log.Info(GetType(), "form-action:Asked question '{0}'", form.Content);

            var categoryAttributes = Repository.Category.Get(form.CategoryId.Value).Attributes;
            var model = new CategoryAttributesThreadFormModel { ThreadForm = form, CategoryAttributes = categoryAttributes };

            if (form.SeoKeywordId.HasValue)
            {
                var categoryAttributeValues = Repository.SEOKeyword.Get(form.SeoKeywordId.Value).CategoryAttributes;
                model.CategoryAttributeValues = CategoryAttributeHelper.GetCategoryAttributeValueModel(categoryAttributeValues);
            }

            if (categoryAttributes.Count == 0)
            {
                PrepareOptions(model.ThreadForm);
                if(!form.DirectQuestionExpertId.HasValue)
                {
                    form.InterestedExpert = GetBestExpertId(form);
                }
                return View(MVC.Thread.Views.Options, model.ThreadForm);
            }

            if (form.TemporaryAttachmentFolder == null)
                form.GenerateTemporaryAttachmentFolder();

            return View(model);
        }