示例#1
0
        public async Task <IActionResult> Edit(Guid topicId, ForumTopicEditModel model)
        {
            if (topicId == null)
            {
                return(this.NotFound());
            }

            var topic = await this.context.ForumTopics.SingleOrDefaultAsync(m => m.Id == topicId);

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

            if (this.ModelState.IsValid)
            {
                topic.Name = model.Name;

                await this.context.SaveChangesAsync();

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

            this.ViewBag.Topic = topic;
            return(this.View(model));
        }
示例#2
0
        public async Task <IActionResult> Edit(Guid id, Guid?forumId, ForumTopicEditModel topic)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var forumTopic = await _context.ForumTopics.SingleOrDefaultAsync(m => m.Id == id);

            if (forumTopic == null)
            {
                return(NotFound());
            }

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

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

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

            if (ModelState.IsValid)
            {
                forumTopic.Name = topic.Name;

                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = id, forumId = forum.Id }));
            }
            ViewData["CreatorId"] = new SelectList(_context.Users, "Id", "Id", forumTopic.CreatorId);
            ViewData["ForumId"]   = new SelectList(_context.Forums, "Id", "Name", forumTopic.ForumId);
            return(View(topic));
        }
示例#3
0
        // GET: ForumTopics/Edit/5
        public async Task <IActionResult> Edit(Guid?id, Guid?forumId)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var forumTopic = await _context.ForumTopics.SingleOrDefaultAsync(m => m.Id == id);

            if (forumTopic == null || !this.userPermissions.CanEditTopic(forumTopic))
            {
                return(NotFound());
            }

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

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

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

            this.ViewBag.Forum   = forum;
            this.ViewBag.TopicId = id;

            ForumTopicEditModel model = new ForumTopicEditModel()
            {
                Name = forumTopic.Name
            };

            ViewData["CreatorId"] = new SelectList(_context.Users, "Id", "Name", forumTopic.CreatorId);
            ViewData["ForumId"]   = new SelectList(_context.Forums, "Id", "Name", forumTopic.ForumId);
            return(View(model));
        }
示例#4
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.CanEditTopic(topic))
            {
                return(this.NotFound());
            }

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

            this.ViewBag.Topic = topic;
            return(this.View(model));
        }
示例#5
0
        public async Task <IActionResult> Create(Guid?forumId, ForumTopicEditModel model)
        {
            if (forumId == null)
            {
                return(this.NotFound());
            }

            var forum = await this.context.Forums
                        .SingleOrDefaultAsync(m => m.Id == forumId);

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

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

            if (this.ModelState.IsValid)
            {
                var now        = DateTime.UtcNow;
                var forumTopic = new ForumTopic
                {
                    Name      = model.Name,
                    CreatorId = user.Id,
                    Created   = now,
                    ForumId   = forum.Id
                };

                this.context.Add(forumTopic);
                await this.context.SaveChangesAsync();

                return(this.RedirectToAction("Index", "Forums", new { forumId = forum.Id }));
                //return this.RedirectToAction("Details", "Forums", new { id = forumCategory.Id });
            }

            this.ViewBag.Forum = forum;
            return(this.View(model));
        }