Пример #1
0
        public async Task <IActionResult> Edit(Guid?id, ForumEditModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var forum = await _context.Forums
                        .SingleOrDefaultAsync(x => x.Id == id);

            if (forum == null | !this.userPermissions.CanEditForum(forum))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                forum.Name        = model.Name;
                forum.Description = model.Description;
                await this._context.SaveChangesAsync();

                return(RedirectToAction("Index", "ForumCategories"));
            }
            ViewBag.ForumCategory = forum.ForumCategory;
            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Edit(Guid forumId, ForumEditModel model)
        {
            if (forumId == null)
            {
                return(this.NotFound());
            }

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

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

            if (this.ModelState.IsValid)
            {
                forum.Name        = model.Name;
                forum.Description = model.Description;
                await this.context.SaveChangesAsync();

                return(this.RedirectToAction("Index", "ForumCategories"));
            }

            this.ViewBag.Forum = forum;
            return(this.View(model));
        }
Пример #3
0
        public async Task <IActionResult> Create(Guid?forumCategoryId, ForumEditModel model)
        {
            if (forumCategoryId == null)
            {
                return(this.NotFound());
            }

            var forumCategory = await this.context.ForumCategories
                                .SingleOrDefaultAsync(m => m.Id == forumCategoryId);

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

            if (this.ModelState.IsValid)
            {
                var forum = new Forum
                {
                    Name            = model.Name,
                    Description     = model.Description,
                    ForumCategoryId = forumCategory.Id
                };

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

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

            this.ViewBag.ForumCategory = forumCategory;
            return(this.View(model));
        }
Пример #4
0
        public async Task <IActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var forum = await _context.Forums.SingleOrDefaultAsync(m => m.Id == id);

            if (forum == null || !this.userPermissions.CanEditForum(forum))
            {
                return(NotFound());
            }
            var model = new ForumEditModel
            {
                Name        = forum.Name,
                Description = forum.Description
            };

            ViewBag.ForumCategory = forum.ForumCategory;
            return(View(model));
        }
Пример #5
0
        public async Task <IActionResult> Edit(Guid?forumId)
        {
            if (forumId == null)
            {
                return(this.NotFound());
            }

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

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

            var model = new ForumEditModel
            {
                Name        = forum.Name,
                Description = forum.Description
            };

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