Пример #1
0
        public void TestAdd()
        {
            mockTopicRepository.Setup(x => x.Add(It.IsAny <Topic>())).Returns(topic);
            var   topicService = new TopicService(mockTopicRepository.Object);
            Topic topicReturn  = topicService.Add(topic);

            Assert.IsNotNull(topicReturn);
        }
Пример #2
0
        public async Task <IActionResult> Create([FromBody] Topic topic)
        {
            if (topic == null)
            {
                return(BadRequest());
            }
            _topicService.Add(topic);
            await _unitOfWork.SaveChangesAsync();

            return(StatusCode(StatusCodes.Status201Created, topic));
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userInfo"] == null)
            {
                string url = Request.Url.ToString();
                Response.Redirect("/Login.aspx?url=" + url);
            }
            else
            {
                SectionService sectionService = new SectionService();

                //板块信息列表
                sectionList = sectionService.GetModelList("");

                sectionId = Int32.Parse(Request["sectionId"]);

                TopicService topicService = new TopicService();

                Topic topicInfo = new Topic();

                if (IsPostBack)
                {
                    sectionId = Int32.Parse(Request["sectionId"]);

                    topicInfo.t_u_id      = ((bbs.Model.User)Session["userInfo"]).id;
                    topicInfo.t_s_id      = Int32.Parse(Request.Form["topic.section.id"]);
                    topicInfo.content     = Request.Form["topic.content"];
                    topicInfo.title       = Request.Form["topic.title"];
                    topicInfo.publishtime = DateTime.Now;
                    topicInfo.good        = "0";
                    topicInfo.top         = "0";

                    int i = topicService.Add(topicInfo); //topic表的id值

                    if (i > 0)
                    {
                        topicInfo.id         = i; //板块主键ID
                        Session["topicInfo"] = topicInfo;
                        Response.Redirect("/topic/TopicList.aspx?sectionId=" + topicInfo.t_s_id);
                    }
                    else
                    {
                        ErrorMsg = "发布失败,请重新发布!";
                    }
                }
            }
        }
Пример #4
0
        public async Task <IActionResult> Add([FromBody] AddTopicModel model)
        {
            if (model == null)
            {
                return(InvalidRequest());
            }

            var result = await TopicService.Add(model);

            if (result.Success)
            {
                return(Success(result.Data));
            }
            else
            {
                return(Error(result.ErrorMessage));
            }
        }
Пример #5
0
 public ActionResult Index(Topic model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var ListPicture = Session["ListPicture"] as List <Picture>;
             model.ListPicture = ListPicture;
             model.ListPicture.ForEach(x => x.Key = (int)TypeTopic.TienIch);
             if (model != null)
             {
                 var result = false;
                 if (model.id == 0)
                 {
                     model.UpdateDate = DateTime.Now;
                     model.key        = (int)TypeTopic.TienIch;
                     result           = _topicService.Add(model);
                 }
                 else
                 {
                     model.UpdateDate = DateTime.Now;
                     model.key        = (int)TypeTopic.TienIch;
                     result           = _topicService.Update(model, (int)TypeTopic.TienIch);
                 }
                 if (result)
                 {
                     TempData["SuccessMsg"] = "Cập nhật trang tiện ích thành công";
                 }
                 else
                 {
                     TempData["ErrorMsg"] = "Cập nhật trang tiện ích thất bại";
                 }
                 return(RedirectToAction("Index", "TienIch", new { Area = "Admin" }));
             }
             return(Json(GetBaseObjectResult(false, "Thực hiện thất bại")));
         }
         catch (Exception ex)
         {
             return(Json(GetBaseObjectResult(false, "Xảy ra lỗi. Bạn vui lòng thử lại sau !")));
         }
     }
     return(Json(GetBaseObjectResult(false, "Dữ liệu không hợp lệ")));
 }
Пример #6
0
 public ActionResult Index(Topic model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (model != null)
             {
                 var result = false;
                 if (model.id == 0)
                 {
                     model.UpdateDate = DateTime.Now;
                     model.key        = (int)TypeTopic.LienHe;
                     result           = _topicService.Add(model);
                 }
                 else
                 {
                     model.UpdateDate = DateTime.Now;
                     model.key        = (int)TypeTopic.LienHe;
                     result           = _topicService.Update(model);
                 }
                 if (result)
                 {
                     TempData["SuccessMsg"] = "Cập nhật trang liên hệ thành công";
                 }
                 else
                 {
                     TempData["ErrorMsg"] = "Cập nhật trang liên hệ thất bại";
                 }
                 return(RedirectToAction("Index", "LienHe", new { Area = "Admin" }));
             }
             return(Json(GetBaseObjectResult(false, "Thực hiện thất bại")));
         }
         catch (Exception ex)
         {
             return(Json(GetBaseObjectResult(false, "Xảy ra lỗi. Bạn vui lòng thử lại sau !")));
         }
     }
     return(Json(GetBaseObjectResult(false, "Dữ liệu không hợp lệ")));
 }
Пример #7
0
        public ActionResult Create(CreateEditTopicViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var cats = _categoryService.GetAllowedEditCategories(UsersRole);
                if (cats.Count > 0)
                {
                    if (ModelState.IsValid)
                    {
                        if (CheckCats(viewModel.Category, cats))
                        {
                            var topic = new Topic();
                            var post  = new Post();

                            topic.Name              = viewModel.Name;
                            topic.Category_Id       = viewModel.Category;
                            topic.IsLocked          = viewModel.IsLocked;
                            topic.IsSticky          = viewModel.IsSticky;
                            topic.MembershipUser_Id = LoggedOnReadOnlyUser.Id;
                            topic.Id = post.Id;

                            post.PostContent       = viewModel.Content;
                            post.MembershipUser_Id = LoggedOnReadOnlyUser.Id;
                            post.Topic_Id          = topic.Id;
                            post.IsTopicStarter    = true;



                            try
                            {
                                _topicServic.Add(topic);
                                _postSevice.Add(post);



                                unitOfWork.Commit();
                            }
                            catch (Exception ex)
                            {
                                LoggingService.Error(ex.Message);
                                unitOfWork.Rollback();
                            }
                        }
                        else
                        {
                            //viewModel.Category = null;
                            //No permission to create a Poll so show a message but create the topic
                            //TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                            //{
                            //    Message = LocalizationService.GetResourceString("Errors.NoPermissionCatergory"),
                            //    MessageType = GenericMessages.info
                            //};
                            ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Errors.CatergoryMessage"));
                        }
                    }
                    viewModel.Categories = _categoryService.GetBaseSelectListCategories(cats);
                    return(View(viewModel));
                }
                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission")));
            }
        }
        public ActionResult Create(CreateTopicViewModel topicViewModel)
        {
            if (ModelState.IsValid)
            {
                // Quick check to see if user is locked out, when logged in
                if (CurrentMember.IsLockedOut || CurrentMember.DisablePosting == true || !CurrentMember.IsApproved)
                {
                    MemberService.LogOff();
                    return(ErrorToHomePage(Lang("Errors.NoPermission")));
                }

                var      successfullyCreated = false;
                var      moderate            = false;
                Category category;
                var      topic = new Topic();

                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    // Before we do anything DB wise, check it contains no bad links
                    if (BannedLinkService.ContainsBannedLink(topicViewModel.TopicContent))
                    {
                        ShowMessage(new GenericMessageViewModel
                        {
                            Message     = Lang("Errors.BannedLink"),
                            MessageType = GenericMessages.Danger
                        });
                        return(Redirect(Urls.GenerateUrl(Urls.UrlType.TopicCreate)));
                    }

                    // Not using automapper for this one only, as a topic is a post and topic in one
                    category = CategoryService.Get(topicViewModel.Category);

                    // First check this user is allowed to create topics in this category
                    var permissions = PermissionService.GetPermissions(category, _membersGroup, MemberService, CategoryPermissionService);

                    // Check this users role has permission to create a post
                    if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked || !permissions[AppConstants.PermissionCreateTopics].IsTicked)
                    {
                        // Throw exception so Ajax caller picks it up
                        ModelState.AddModelError(string.Empty, Lang("Errors.NoPermission"));
                    }
                    else
                    {
                        // We get the banned words here and pass them in, so its just one call
                        // instead of calling it several times and each call getting all the words back


                        topic = new Topic
                        {
                            Name       = BannedWordService.SanitiseBannedWords(topicViewModel.TopicName, Dialogue.Settings().BannedWords),
                            Category   = category,
                            CategoryId = category.Id,
                            Member     = CurrentMember,
                            MemberId   = CurrentMember.Id
                        };

                        // See if the user has actually added some content to the topic
                        if (!string.IsNullOrEmpty(topicViewModel.TopicContent))
                        {
                            // Check for any banned words
                            topicViewModel.TopicContent = BannedWordService.SanitiseBannedWords(topicViewModel.TopicContent, Dialogue.Settings().BannedWords);

                            // See if this is a poll and add it to the topic
                            if (topicViewModel.PollAnswers != null && topicViewModel.PollAnswers.Any(x => !string.IsNullOrEmpty(x.Answer)))
                            {
                                // Do they have permission to create a new poll
                                if (permissions[AppConstants.PermissionCreatePolls].IsTicked)
                                {
                                    // Create a new Poll
                                    var newPoll = new Poll
                                    {
                                        Member   = CurrentMember,
                                        MemberId = CurrentMember.Id
                                    };

                                    // Create the poll
                                    PollService.Add(newPoll);

                                    // Save the poll in the context so we can add answers
                                    unitOfWork.SaveChanges();

                                    // Now sort the answers
                                    var newPollAnswers = new List <PollAnswer>();
                                    foreach (var pollAnswer in topicViewModel.PollAnswers)
                                    {
                                        // Attach newly created poll to each answer
                                        pollAnswer.Poll = newPoll;
                                        PollService.Add(pollAnswer);
                                        newPollAnswers.Add(pollAnswer);
                                    }
                                    // Attach answers to poll
                                    newPoll.PollAnswers = newPollAnswers;

                                    // Save the new answers in the context
                                    unitOfWork.SaveChanges();

                                    // Add the poll to the topic
                                    topic.Poll = newPoll;
                                }
                                else
                                {
                                    //No permission to create a Poll so show a message but create the topic
                                    ShowMessage(new GenericMessageViewModel
                                    {
                                        Message     = Lang("Errors.NoPermissionPolls"),
                                        MessageType = GenericMessages.Info
                                    });
                                }
                            }

                            // Check for moderation
                            if (category.ModerateAllTopicsInThisCategory)
                            {
                                topic.Pending = true;
                                moderate      = true;
                            }


                            // Create the topic
                            topic = TopicService.Add(topic);

                            // Save the changes
                            unitOfWork.SaveChanges();

                            // Now create and add the post to the topic
                            TopicService.AddLastPost(topic, topicViewModel.TopicContent, PostService);

                            // Update the users points score for posting
                            MemberPointsService.Add(new MemberPoints
                            {
                                Points        = Settings.PointsAddedPerNewPost,
                                Member        = CurrentMember,
                                MemberId      = CurrentMember.Id,
                                RelatedPostId = topic.LastPost.Id
                            });

                            // Now check its not spam
                            var akismetHelper = new AkismetHelper();
                            if (akismetHelper.IsSpam(topic))
                            {
                                // Could be spam, mark as pending
                                topic.Pending = true;
                            }

                            // Subscribe the user to the topic as they have checked the checkbox
                            if (topicViewModel.SubscribeToTopic)
                            {
                                // Create the notification
                                var topicNotification = new TopicNotification
                                {
                                    Topic    = topic,
                                    Member   = CurrentMember,
                                    MemberId = CurrentMember.Id
                                };
                                //save
                                TopicNotificationService.Add(topicNotification);
                            }

                            try
                            {
                                unitOfWork.Commit();
                                if (!moderate)
                                {
                                    successfullyCreated = true;
                                }

                                // Update the users post count
                                MemberService.AddPostCount(CurrentMember);
                            }
                            catch (Exception ex)
                            {
                                unitOfWork.Rollback();
                                LogError(ex);
                                ModelState.AddModelError(string.Empty, Lang("Errors.GenericMessage"));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, Lang("Errors.GenericMessage"));
                        }
                    }
                }

                using (UnitOfWorkManager.NewUnitOfWork())
                {
                    if (successfullyCreated)
                    {
                        // Success so now send the emails
                        NotifyNewTopics(category);

                        // Redirect to the newly created topic
                        return(Redirect($"{topic.Url}?postbadges=true"));
                    }
                    if (moderate)
                    {
                        // Moderation needed
                        // Tell the user the topic is awaiting moderation
                        return(MessageToHomePage(Lang("Moderate.AwaitingModeration")));
                    }
                }
            }

            ShowMessage();
            return(Redirect(Urls.GenerateUrl(Urls.UrlType.TopicCreate)));
        }
Пример #9
0
        public ActionResult Index(MatBangViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var ListPicture = new List <Picture>();
                    if (model != null)
                    {
                        var result = false;
                        if (model.Id > 0)
                        {
                            var obj = _topicService.GetById(model.Id);
                            obj.ShortDescription = model.MoTa;
                            obj.ContentDetail    = model.MatBangChiTiet;
                            _topicService.Update(obj);
                        }
                        else
                        {
                            var obj = new Topic
                            {
                                ShortDescription = model.MoTa,
                                ContentDetail    = model.MatBangChiTiet,
                                key = (int)TypeTopic.MatBang
                            };
                            _topicService.Add(obj);
                        }
                        var matBangtienIch = new Picture
                        {
                            id  = model.MatBangTienIchId,
                            Url = model.UrlMatBangTienIch,
                            Key = (int)TypeTopic.MatBangTienIch
                        };
                        ListPicture.Add(matBangtienIch);
                        var matBangtongThe = new Picture
                        {
                            id  = model.MatBangTongTheId,
                            Url = model.UrlMatBangTongThe,
                            Key = (int)TypeTopic.MatBangTongThe
                        };
                        ListPicture.Add(matBangtongThe);
                        result = _pictureService.UpdateMatBang(ListPicture);

                        if (result)
                        {
                            TempData["SuccessMsg"] = "Cập nhật trang mặt bằng thành công";
                        }
                        else
                        {
                            TempData["ErrorMsg"] = "Cập nhật trang mặt bằng thất bại";
                        }
                        return(RedirectToAction("Index", "MatBang", new { Area = "Admin" }));
                    }
                    return(Json(GetBaseObjectResult(false, "Thực hiện thất bại")));
                }
                catch (Exception ex)
                {
                    return(Json(GetBaseObjectResult(false, "Xảy ra lỗi. Bạn vui lòng thử lại sau !")));
                }
            }
            return(Json(GetBaseObjectResult(false, "Dữ liệu không hợp lệ")));
        }
Пример #10
0
        public ActionResult Create(AdminCreateEditTopicViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var cats = _categoryService.GetAllowedEditCategories(UsersRole, false);
                if (cats.Count > 0)
                {
                    if (ModelState.IsValid)
                    {
                        if (CheckCats(viewModel.Category, cats))
                        {
                            var topic = new Topic();
                            var post  = new Post();

                            topic.Name              = viewModel.Name;
                            topic.Category_Id       = viewModel.Category;
                            topic.Image             = viewModel.Image;
                            topic.IsLocked          = viewModel.IsLocked;
                            topic.IsSticky          = viewModel.IsSticky;
                            topic.MembershipUser_Id = LoggedOnReadOnlyUser.Id;
                            topic.Post_Id           = post.Id;

                            topic.Intro          = viewModel.Intro;
                            topic.SEOKeyword     = viewModel.SEOKeyword;
                            topic.SEODescription = viewModel.SEODescription;

                            post.PostContent       = viewModel.Content;
                            post.MembershipUser_Id = LoggedOnReadOnlyUser.Id;
                            post.Topic_Id          = topic.Id;
                            post.IsTopicStarter    = true;

                            topic.ShotContent       = string.Concat(StringUtils.ReturnAmountWordsFromString(StringUtils.StripHtmlFromString(post.PostContent), 50), "....");
                            topic.isAutoShotContent = true;
                            var i = topic.ShotContent.Length;
                            if (i > 450)
                            {
                                topic.ShotContent = topic.ShotContent.Substring(0, 440) + "...";
                            }

                            try
                            {
                                _topicServic.Add(topic);
                                _postSevice.Add(post);


                                unitOfWork.Commit();

                                return(RedirectToAction("Edit", new { Id = topic.Id }));
                            }
                            catch (Exception ex)
                            {
                                LoggingService.Error(ex.Message);
                                unitOfWork.Rollback();
                            }
                        }
                        else
                        {
                            //viewModel.Category = null;
                            //No permission to create a Poll so show a message but create the topic
                            //TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                            //{
                            //    Message = LocalizationService.GetResourceString("Errors.NoPermissionCatergory"),
                            //    MessageType = GenericMessages.info
                            //};
                            ModelState.AddModelError(string.Empty, LocalizationService.GetResourceString("Errors.CatergoryMessage"));
                        }
                    }
                    viewModel.Categories = _categoryService.GetBaseSelectListCategories(cats);
                    return(View(viewModel));
                }
                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission")));
            }
        }