Esempio n. 1
0
        public ActionResult CreateTopic(TopicCreationModel model)
        {
            var user     = HttpContext.DiscussionUser();
            var userName = user.UserName;

            if (!ModelState.IsValid)
            {
                _logger.LogModelState("创建话题", ModelState, user.Id, userName);
                return(BadRequest());
            }

            try
            {
                var topic = _topicService.CreateTopic(model);
                _logger.LogInformation("创建话题成功:{@NewTopicAttempt}",
                                       new { topic.Title, topic.Id, UserId = user.Id, user.UserName });
                // ReSharper disable once Mvc.ActionNotResolved
                return(RedirectToAction("Index", new { topic.Id }));
            }
            catch (InvalidOperationException ex)
            {
                _logger.LogWarning("创建话题失败:{@NewTopicAttempt}",
                                   new { UserId = user.Id, user.UserName, Result = ex.Message });
                return(BadRequest());
            }
        }
        public IActionResult Create([FromBody] TopicViewModel model)
        {
            // return a generic HTTP Status 500(Server Error)
            // if the client payload is invalid
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            // or if the user does not exist
            var user = _userService.GetUserByUserName(model.Username);

            if (user == null)
            {
                return(new StatusCodeResult(500));
            }

            Topic topic = new Topic()
            {
                Title            = model.Title,
                Description      = model.Description,
                UserId           = user.Id,
                CreatedDate      = DateTime.Now,
                LastModifiedDate = DateTime.Now
            };

            // Call the domain layer to handle the creation
            _topicService.CreateTopic(topic);

            // return an HTTP Status 200 (OK).
            return(new NoContentResult());
        }
Esempio n. 3
0
 public async Task <ActionResult <TopicViewModel> > CreateTopic(
     TopicSaveViewModel topic)
 {
     return(await _topicService
            .CreateTopic(topic)
            .HandleFailuresOrOk());
 }
Esempio n. 4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();
            var description = Server.HtmlEncode(txtDescription.Text);

            description = txtDescription.Text;
            var topic = new DiscussionForum.Domain.DomainModel.Topic(currentUser.Id, int.Parse(ddlCategories.SelectedItem.Value), txtTitle.Text, description);

            int topicId = _topicService.CreateTopic(topic);

            if (topicId == -1)
            {
                error.InnerText = "A topic with this title already exists, please check it out, and rename your topic if necessary.";
            }
            else
            {
                var topicFollower = new TopicFollower(topicId, currentUser.Id);
                _topicService.FollowTopic(topicFollower);

                var category = _categoryService.GetCategoryById(topic.CategoryID);

                string message = $@"<strong>{currentUser.FullName}</strong> created new topic <a href='/topic/{topic.ID}'>{topic.Title}</a> in category <a href='/category/'{category.ID}'>{category.Name}</a>.";

                var followers = _categoryService.GetFollowers(category.ID);

                foreach (var follower in followers)
                {
                    Notification notification = new Notification(follower.FollowerID, message, DateTime.Now);
                    _notificationService.CreateNotification(notification);
                }

                Response.RedirectToRoute("TopicRoute", new { id = topicId });
            }
        }
Esempio n. 5
0
        public ActionResult Create(CreateTopicViewModel createTopicView)
        {
            var createTopicDto = Mapper.Map <CreateTopicDto>(createTopicView);

            _topicService.CreateTopic(createTopicDto);

            return(RedirectToAction("Item", "Section", new { Id = createTopicView.SectionId }));
        }
Esempio n. 6
0
        public async Task <ActionResult <TopicModel> > PostTopic(string name)
        {
            if (name == "")
            {
                return(BadRequest());
            }

            await _topicService.CreateTopic(name).ConfigureAwait(false);

            return(Ok());
        }
        public async Task <ActionResult> Create(CreateTopicModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await _service.CreateTopic(model.Title, model.SubjectId, UserData.Id);

            return(RedirectToAction("TopicList", new { subjectId = model.SubjectId }));
        }
Esempio n. 8
0
        public IFluentQueueApi CreateTopic(string topicId)
        {
            topicId.ThrowExceptionIfNullOrEmpty("topicId");
            ValidateProjectIdIsSet();

            _topicService.CreateTopic(_projectId, topicId);

            _topicId = topicId;

            return(this);
        }
Esempio n. 9
0
        public async Task <IActionResult> CreateTopic([FromForm] string nameOfTopic)
        {
            nameOfTopic = nameOfTopic ?? throw new ArgumentNullException(nameof(nameOfTopic));

            var topicResult = await topicService.CreateTopic(User.Identity.Name, nameOfTopic);

            if (topicResult.IsSuccessed)
            {
                return(CreatedAtAction(nameof(CreateTopic), topicResult.Data));
            }

            throw topicResult.Exception;
        }
Esempio n. 10
0
        public TopicViewModel(ITopicService topicService, IQuizService quizService)
        {
            this.topicService = topicService;
            this.quizService  = quizService;
            //var topic = topicService.GetAllTopics();
            //MessageBox.Show(topic.FirstOrDefault().Text);
            //MessageBox.Show(topic.Text);
            //MessageBox.Show(topicService.GetTopicById(1).Text);
            var topic = new Topic("from constructor");

            topicService.CreateTopic(topic);
            //MessageBox.Show(topic.Text);
        }
Esempio n. 11
0
        public async Task <IActionResult> CreateTopic([FromBody] TopicDto topicDto)
        {
            try
            {
                await _workWithTopic.CreateTopic(topicDto);

                return(Ok());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(Problem(ex.Message));
            }
        }
Esempio n. 12
0
        public async Task Create_RepositoryInvokes()
        {
            //Arrange
            var topic = _fakeData.Topics.Last();

            var topicDto = new TopicDto
            {
                Name   = topic.Name,
                UserId = topic.UserId
            };

            //Act
            await _topicService.CreateTopic(topicDto);

            //Assert
            _topicRepositoryMock.Verify(r => r.Create(It.IsAny <Topic>()));
            _unitOfWorkMock.Verify(uow => uow.Users);
            _unitOfWorkMock.Verify(uow => uow.Topics);
        }
Esempio n. 13
0
        public async Task <IActionResult> CreateNewTopic(TopicViewModel topicView)
        {
            if (Request.Form.Files.Count != 1)
            {
                ModelState.AddModelError("Image", "image cannot be empty");
            }
            else
            {
                topicView.TopicPicture = ImageConvertor.ConvertImageToBytes(Request.Form.Files[0]);
            }

            if (ModelState.IsValid)
            {
                var mappedTopic = mapper.Map <TopicDTO>(topicView);
                await topicService.CreateTopic(mappedTopic);

                return(RedirectToAction(nameof(Panel)));
            }
            return(View(topicView));
        }
Esempio n. 14
0
        public ActionResult CreateTopic(TopicCreationModel model)
        {
            var userName = HttpContext.DiscussionUser().UserName;

            if (!ModelState.IsValid)
            {
                _logger.LogModelState("创建话题", ModelState, userName);
                return(BadRequest());
            }

            try
            {
                var topic = _topicService.CreateTopic(model);
                _logger.LogInformation($"创建话题成功:{userName}:{topic.Title}(id: {topic.Id})");
                return(RedirectToAction("Index", new { topic.Id }));
            }
            catch (UserVerificationRequiredException ex)
            {
                _logger.LogWarning($"创建话题失败:{userName}:{ex.Message}");
                return(BadRequest());
            }
        }
Esempio n. 15
0
        // POST api/<controller>
        public void Post(CreateTopicViewModel createTopicView)
        {
            var createTopicDto = Mapper.Map <CreateTopicDto>(createTopicView);

            _topicService.CreateTopic(createTopicDto);
        }