Example #1
0
        public ThreadFormModel(IEnumerable<Category> availableCategories)
        {
            AvailableCategories = availableCategories;
            AvailableCategoriesItems = CategoryHelper.GetCategoryListItems(availableCategories, Resources.Thread.SelectCategory);

            ThreadForm = new ThreadForm();
            if(ThreadForm.TemporaryAttachmentFolder == null)
                ThreadForm.GenerateTemporaryAttachmentFolder();
        }
Example #2
0
        private int GetBestExpertId(ThreadForm form)
        {
            var categoryAttributes = new CategoryAttributeHelper().GetCategoryAttributeValues(form.AttributeValues).ToList();
            var experts = Repository.Expert.FindClosestMatches(form.CategoryId.Value, categoryAttributes, 10);

            var bestExpert = experts.First();
            var bestMatch = Repository.Expert.GetMatch(bestExpert, form.CategoryId.Value, categoryAttributes);

            var activeExpertsIds = ActiveUsersHelper.GetActivePublicExpertsIds(form.CategoryId);
            var bestActiveExpert = experts.FirstOrDefault(e => activeExpertsIds.Contains(e.Id));
            if (bestActiveExpert == null)
                return bestExpert.Id;

            var bestActiveMatch = Repository.Expert.GetMatch(bestActiveExpert, form.CategoryId.Value, categoryAttributes);

            return (double) bestActiveMatch/bestMatch > 0.8 ? bestActiveExpert.Id : bestExpert.Id;
        }
Example #3
0
        private void SetValue(ThreadForm model)
        {
            var baseValue = Repository.Category.GetValue(model.CategoryId.Value, ThreadPriority.Medium, model.Verbosity);

            var categoryAttributes = new CategoryAttributeHelper().GetCategoryAttributeValues(model.AttributeValues).ToList();
            var priceModifier = 1 + categoryAttributes.Sum(ca => ca.SelectedOptions.Sum(o => o.PriceModifier));

            model.Value = Math.Round(baseValue*priceModifier, 0);
        }
Example #4
0
        private void PrepareOptions(ThreadForm model)
        {
            model.Priority = ThreadPriority.Medium;
            model.Verbosity = ThreadVerbosity.Medium;
            SetValue(model);

            ThreadMemoryHelper.RememberThread(model);
        }
Example #5
0
        public virtual ActionResult Question(ThreadForm form)
        {
            var model = new Question
                            {
                                ThreadForm = form,
                                Category = Repository.Category.Get(form.CategoryId.Value)
                            };

            return PartialView(MVC.Thread.Views._Question, model);
        }
Example #6
0
 public virtual ActionResult UserDefinedPriceForm(ThreadForm form)
 {
     return PartialView(new UserDefinedPriceForm{});
 }
Example #7
0
        public virtual ActionResult Save(ThreadForm form)
        {
            ThreadMemoryHelper.PopRememberedThread();

            if (!ModelState.IsValid)
            {
                
                Log.Info(GetType(),"Thread Save Validation Failed with errors: {0}",string.Join(";",ModelState.SelectMany(keyValuePair => keyValuePair.Value.Errors).Select(x => x.ErrorMessage)));
                return View(MVC.Thread.Views.Options, form);
            }

            var thread = Mapper.Map<Thread>(form);

            var helper = new CategoryAttributeHelper();
            var categoryAttributes = helper.GetCategoryAttributeValues(form.AttributeValues).ToList();
            foreach (var categoryAttributeValue in categoryAttributes)
                thread.CategoryAttributes.Add(categoryAttributeValue);

            thread.Author = AuthenticationHelper.CurrentUser;
            thread.Category = Repository.Category.Get(form.CategoryId.Value);

            if (form.CustomValue == null)
                thread.Value = Repository.Category.GetValue(form.CategoryId.Value, ThreadPriority.Medium, form.Verbosity);

            thread.Posts.First().Author = AuthenticationHelper.CurrentUser;
            thread.Posts.First().Type = PostType.Question;

            var brokerId = BrokerHelper.GetBrokerIdFromCookie();
            if (brokerId != null)
                thread.Broker = Repository.User.Get(brokerId.Value);

            Repository.Thread.Add(thread);
            
            if (form.DirectQuestionExpertId != null) { DirectQuestion(form.DirectQuestionExpertId.Value, thread.Id); }

            if (form.CustomValue != null) { EventLog.Event<UserDefinedPriceEvent>(thread); }

            form.PaymentForm.RelatedId = thread.Id;

            var attachmentsDirPath = HttpContext.Server.MapPath("~/Attachments/");
            if (Directory.Exists(attachmentsDirPath + form.TemporaryAttachmentFolder)) { MoveAttachmentsFromTemporaryFolder(form.TemporaryAttachmentFolder, thread.Id); }

            var provisionData = "\r\n" + "Prowizja eksperta: " + thread.ExpertProvision.ToString() + 
                "\r\n" + "Prowizja brokera: " + thread.BrokerProvision.ToString();
            EventLog.Event<NewThreadEvent>(thread, provisionData);

            var model = form.PaymentForm.PreparePayment(Url);

            if (model.ImmediateRedirectActionResult != null)
                return RedirectToAction(model.ImmediateRedirectActionResult);

            return View(MVC.Payment.Views.PaymentRedirect, model);
        }
Example #8
0
 public virtual ActionResult GetThreadVerbocity(ThreadForm model)
 {
     return Json(model.Verbosity.ToString());
 }
Example #9
0
 public virtual ActionResult GetThreadValue(ThreadForm model)
 {
     SetValue(model);
     return Json(model.Value.ToString("G"));
 }
Example #10
0
 public static ThreadForm PopRememberedThread()
 {
     var result = RememberedThread;
     RememberedThread = null;
     return result;
 }
Example #11
0
 public static void RememberThread(ThreadForm threadForm)
 {
     RememberedThread = threadForm;
 }
Example #12
0
        public virtual ActionResult QuestionListSeo(int keywordId, string title)
        {
            var keyword = Repository.SEOKeyword.Get(keywordId);
            PresetSeoKeyword(keyword);

            var threads = Repository.Thread.FindClosestMatches(keyword.Category,
                                                               keyword.CategoryAttributes,
                                                               PagerHelper.SeoSimiliarThreadsLimit,
                                                               t => t.BySanitizationStatus(ThreadSanitizationStatus.Sanitized).ByInnerStatus(false));

            var experts = Repository.Expert.FindClosestMatches(keyword.Category.Id,
                                                               keyword.CategoryAttributes,
                                                               PagerHelper.SimiliarExpertsListSize);

            var form = new ThreadForm()
                           {
                               Content = keyword.Phrase,
                               CategoryId = keyword.Category.Id,
                               AttributeValues =
                                   CategoryAttributeHelper.GetCategoryAttributeValueModel(keyword.CategoryAttributes),
                               SeoKeywordId = keywordId
                           };

            form.GenerateTemporaryAttachmentFolder();

            var seo = new SeoDetails()
                          {
                              Id = keyword.Id,
                              Phrase = keyword.Phrase,
                              Category = keyword.Category,
                              Type = keyword.Type,
                              Status = keyword.Status
                          };

            var categories = new List<Category>();
            categories.Add(keyword.Category);

            var model = new ThreadDetailsSeo()
                            {
                                SeoDetails = seo,
                                ThreadForm = form,
                                Threads = threads,
                                Experts = experts,
                                AvailableCategories = categories
                            };

            ViewBag.PageTitle = model.SeoDetails.Phrase;

            return View(model);
        }
Example #13
0
        public virtual ActionResult ExpertListSeo(int keywordId, string title)
        {
            var keyword = Repository.SEOKeyword.Get(keywordId);
            PresetSeoKeyword(keyword);

            var experts = Repository.Expert.FindClosestMatches(keyword.Category.Id, keyword.CategoryAttributes,
                                                               PagerHelper.SeoSimiliarExpertsLimit);

            var form = new ThreadForm()
                           {
                               CategoryId = keyword.Category.Id,
                               AttributeValues =
                                   CategoryAttributeHelper.GetCategoryAttributeValueModel(keyword.CategoryAttributes),
                               SeoKeywordId = keywordId
                           };

            form.GenerateTemporaryAttachmentFolder();

            var seo = new SeoDetails()
                          {
                              Id = keyword.Id,
                              Phrase = keyword.Phrase,
                              Category = keyword.Category,
                              Type = keyword.Type,
                              Status = keyword.Status
                          };

            var categories = new List<Category>();
            categories.Add(keyword.Category);

            var model = new ThreadDetailsSeo(Repository.Category.All())
                            {
                                SeoDetails = seo,
                                Experts = experts,
                                ThreadForm = form,
                                AvailableCategories = categories
                            };

            ViewBag.PageTitle = model.SeoDetails.Phrase;

            return View(model);
        }