コード例 #1
0
ファイル: ThreadFormModel.cs プロジェクト: bwrobel/Experts
        public ThreadFormModel(IEnumerable<Category> availableCategories)
        {
            AvailableCategories = availableCategories;
            AvailableCategoriesItems = CategoryHelper.GetCategoryListItems(availableCategories, Resources.Thread.SelectCategory);

            ThreadForm = new ThreadForm();
            if(ThreadForm.TemporaryAttachmentFolder == null)
                ThreadForm.GenerateTemporaryAttachmentFolder();
        }
コード例 #2
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
        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;
        }
コード例 #3
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
        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);
        }
コード例 #4
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
        private void PrepareOptions(ThreadForm model)
        {
            model.Priority = ThreadPriority.Medium;
            model.Verbosity = ThreadVerbosity.Medium;
            SetValue(model);

            ThreadMemoryHelper.RememberThread(model);
        }
コード例 #5
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
        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);
        }
コード例 #6
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
 public virtual ActionResult UserDefinedPriceForm(ThreadForm form)
 {
     return PartialView(new UserDefinedPriceForm{});
 }
コード例 #7
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
        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);
        }
コード例 #8
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
 public virtual ActionResult GetThreadVerbocity(ThreadForm model)
 {
     return Json(model.Verbosity.ToString());
 }
コード例 #9
0
ファイル: ThreadController.cs プロジェクト: bwrobel/Experts
 public virtual ActionResult GetThreadValue(ThreadForm model)
 {
     SetValue(model);
     return Json(model.Value.ToString("G"));
 }
コード例 #10
0
ファイル: ThreadMemoryHelper.cs プロジェクト: bwrobel/Experts
 public static ThreadForm PopRememberedThread()
 {
     var result = RememberedThread;
     RememberedThread = null;
     return result;
 }
コード例 #11
0
ファイル: ThreadMemoryHelper.cs プロジェクト: bwrobel/Experts
 public static void RememberThread(ThreadForm threadForm)
 {
     RememberedThread = threadForm;
 }
コード例 #12
0
ファイル: CatalogController.cs プロジェクト: bwrobel/Experts
        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);
        }
コード例 #13
0
ファイル: CatalogController.cs プロジェクト: bwrobel/Experts
        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);
        }