public ActionResult Create(NewTopicModel topic)
 {
     using (NHibernate.ISession session = nHibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             var aTopic = new Topic
             {
                 Category = session.Query <Category>().Single(x => x.Id == topic.CategoryId),
                 Name     = topic.Name,
                 Date     = DateTime.Now,
                 User     = session.Query <User>().Single(x => x.Email == User.Identity.Name),
                 IsClosed = false,
             };
             var initMsg = new ForumMessage
             {
                 Text  = topic.InitialText,
                 User  = aTopic.User,
                 Date  = aTopic.Date,
                 Topic = aTopic,
             };
             aTopic.Messages.Add(initMsg);
             session.SaveOrUpdate(aTopic);
             session.SaveOrUpdate(initMsg);
             transaction.Commit();
             var dbTopic = session.Query <Topic>().Single(x => x.Name == aTopic.Name && x.Date == aTopic.Date);
             return(CreatedAtRoute("GetTopic", new { id = dbTopic.Id }, new TopicAPIModel(dbTopic)));
         }
     }
 }
Beispiel #2
0
        public async Task <IActionResult> Create(NewTopicModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = _userManager.GetUserId(User);
                var user   = await _userManager.FindByIdAsync(userId);

                var topic = new Topic
                {
                    Title = model.Title,
                    Forum = _forumService.GetById(model.ForumId)
                };
                var post = new Post
                {
                    Content = model.Content,
                    Created = DateTime.Now,
                    User    = user,
                    Topic   = topic,
                    IsHead  = true
                };

                await _topicService.Add(topic);

                await _postService.Add(post);

                return(RedirectToAction("Topics", "Forum", new { id = model.ForumId }));
            }
            return(View(model));
        }
Beispiel #3
0
        //protected async Task OnChange(ProjectType value)
        //{
        //    await LoadProjects(value);
        //    form?.Refresh();
        //    RequireRender = true;
        //    bverNoSelect?.Refresh();
        //    MarkAsRequireRender();
        //    StateHasChanged();
        //}

        protected override async Task InitilizePageDataAsync()
        {
            article = new NewTopicModel()
            {
                Title = "", Content = ""
            };
            //await LoadProjects(ProjectType.Element);
        }
        //protected async Task OnChange(ProjectType value)
        //{
        //    await LoadProjects(value);
        //    form?.Refresh();
        //    RequireRender = true;
        //    bverNoSelect?.Refresh();
        //    MarkAsRequireRender();
        //    StateHasChanged();
        //}

        protected override async Task InitilizePageDataAsync()
        {
            await LoadProjects();

            article = new NewTopicModel()
            {
                Title = "", Content = "", VerNo = bZVersions.FirstOrDefault()?.VerNo
            };
        }
Beispiel #5
0
        public IActionResult Create(int id)
        {
            var forum = _forumService.GetById(id);

            if (forum != null)
            {
                var model = new NewTopicModel
                {
                    ForumTitle       = forum.Title,
                    ForumId          = forum.Id,
                    TopicStarterName = User.Identity.Name
                };

                return(View(model));
            }

            return(RedirectToAction("Index", "Forum"));
        }
Beispiel #6
0
 public async Task <ActionResult> Create(NewTopicModel model)
 {
     if (ModelState.IsValid)
     {
         var topic = new Topic
         {
             CategoryId = model.CategoryId,
             Name       = model.Name,
             User       = await _users.GetByEmailAsync(User.Identity.Name),
             IsClosed   = false,
         };
         var msg = new ForumMessage(model.InitialText, topic.Id, topic.User.Id);
         if (await _topics.CreateAsync(topic, msg, User.Identity.Name))
         {
             return(Ok(topic));
         }
         else
         {
             ModelState.AddModelError("", _topics.LastError);
             return(BadRequest(model));
         }
     }
     return(BadRequest(model));
 }
Beispiel #7
0
        private async Task AddTopic(NewTopicModel newTopicModel)
        {
            var User = await GetUser();

            BZTopicDto bZTopicDto = new BZTopicDto()
            {
                Content   = newTopicModel.Content,
                Title     = newTopicModel.Title,
                Category  = (int)newTopicModel.Category,
                CreatorId = User.Id,
                //VersionId = bZVersions.FirstOrDefault(p => p.VerNo == newTopicModel.VerNo)?.Id,
                LastModifyDate = DateTime.Now,
                CreateDate     = DateTime.Now,
                Good           = 0,
                Hot            = 0,
                ReplyCount     = 0,
                Status         = 0,
                Top            = 0,
            };

            await WithFullScreenLoading(async() =>
            {
                var result = await NetService.AddTopic(bZTopicDto, newTopicModel.Notice);

                if (result.IsSuccess)
                {
                    ToastSuccess("发布成功");
                    await Task.Delay(100);
                    NavigationManager.NavigateTo($"/topic/{result.Data}");
                }
                else
                {
                    ToastError($"发布失败{result.Message}");
                }
            });
        }