示例#1
0
        public async Task <IActionResult> Create(Guid?ForumId, ForumTopicCreateModel model)
        {
            if (ForumId == null)
            {
                return(this.NotFound());
            }

            var forum = await this._context.Forums
                        .SingleOrDefaultAsync(x => x.Id == ForumId);

            if (forum == null)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                var topic = new ForumTopic
                {
                    ForumId           = forum.Id,
                    Name              = model.Name,
                    Created           = DateTime.Now,
                    ApplicationUserId = _userManager.GetUserId(User)
                                        // ApplicationUser = _userManager.GetUserName(User) если б поле имя в appuser добавил
                };

                this._context.Add(topic);
                await this._context.SaveChangesAsync();

                return(this.RedirectToAction("Index", new { forumId = forum.Id }));
            }

            this.ViewBag.Forum = forum;
            return(this.View(model));
        }
示例#2
0
        public async Task <IActionResult> Edit(Guid?TopicId, ForumTopicCreateModel model)
        {
            if (TopicId == null)
            {
                return(this.NotFound());
            }

            var topic = await this._context.ForumTopics
                        .SingleOrDefaultAsync(m => m.Id == TopicId);

            if (topic == null)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                topic.Name              = model.Name;
                topic.Created           = DateTime.Now;
                topic.ApplicationUserId = _userManager.GetUserId(User);

                await this._context.SaveChangesAsync();

                return(this.RedirectToAction("Index", new { forumId = topic.ForumId }));
            }

            return(this.View(model));
        }
示例#3
0
        // GET: ForumTopics/Edit/5
        public async Task <IActionResult> Edit(Guid?TopicId)
        {
            if (TopicId == null)
            {
                return(this.NotFound());
            }

            var topic = await this._context.ForumTopics
                        .SingleOrDefaultAsync(m => m.Id == TopicId);

            // if (topic == null || !this.userPermissions.CanEditPostComment(postComment))
            if (topic == null)
            {
                return(this.NotFound());
            }

            var model = new ForumTopicCreateModel
            {
                Name = topic.Name
            };

            return(this.View(model));
        }
示例#4
0
        public async Task <IActionResult> Create(Guid?forumId, ForumTopicCreateModel forumTopic)
        {
            if (forumId == null)
            {
                return(this.NotFound());
            }

            var forum = await this._context.Forums
                        .SingleOrDefaultAsync(x => x.Id == forumId);

            if (forum == null)
            {
                return(this.NotFound());
            }

            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

            if (ModelState.IsValid)
            {
                ForumTopic topic = new ForumTopic()
                {
                    Id        = Guid.NewGuid(),
                    Name      = forumTopic.Name,
                    Created   = DateTime.UtcNow,
                    CreatorId = user.Id,
                    ForumId   = forum.Id
                };

                _context.Add(topic);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Forums", new { id = forumId, forumCategoryid = forum.CategoryId }));
            }
            ViewData["CreatorId"] = new SelectList(_context.Users, "Id", "UserName");
            ViewData["ForumId"]   = new SelectList(_context.Forums, "Id", "Name");
            return(View(forumTopic));
        }