Пример #1
0
        public async Task <IActionResult> Create(ForumCreateModel model)
        {
            if (model.ImageUpload != null)
            {
                Uri uri = await Uploader.UploadImage("forum-images", model.ImageUpload, _configuration, _uploadService);

                model.ForumImageUrl = uri.AbsoluteUri;
            }

            if (ModelState.IsValid)
            {
                var forum = new Forum
                {
                    Title       = model.Title,
                    Description = model.Description,
                    Created     = DateTime.Now,
                    ImageUrl    = model.ForumImageUrl
                };

                await _forumService.Add(forum);

                return(RedirectToAction("Index", "Forum"));
            }

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Create(Guid?forumCategoryId, ForumCreateModel model)
        {
            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

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

            var forumCategory = await this._context.ForumCategories
                                .SingleOrDefaultAsync(x => x.Id == forumCategoryId);

            if (forumCategory == null || user == null || !User.IsInRole(ApplicationRoles.Administrators))
            {
                return(this.NotFound());
            }
            if (this.ModelState.IsValid)
            {
                var forum = new Forum
                {
                    ForumCategoryId = (Guid)forumCategoryId,
                    Name            = model.Name,
                    Description     = model.Description
                };
                this._context.Add(forum);
                await this._context.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }
            ViewBag.ForumCategory = forumCategory;
            return(this.View(model));
        }
Пример #3
0
        public async Task <IActionResult> Edit(ForumCreateModel model)
        {
            if (model.ImageUpload != null)
            {
                Uri uri = await Uploader.UploadImage("forum-images", model.ImageUpload, _configuration, _uploadService);

                model.ForumImageUrl = uri.AbsoluteUri;
            }

            if (ModelState.IsValid)
            {
                await _forumService.UpdateForumDescription(model.Id, model.Description);

                await _forumService.UpdateForumImageUrl(model.Id, model.ForumImageUrl);

                await _forumService.UpdateForumTitle(model.Id, model.Title);

                return(RedirectToAction("Index", "Forum"));
            }

            return(View(model));
        }
Пример #4
0
        public IActionResult Edit(int id)
        {
            if (User.IsInRole("Admin"))
            {
                var forum = _forumService.GetById(id);

                if (forum != null)
                {
                    var model = new ForumCreateModel
                    {
                        Id            = id,
                        Title         = forum.Title,
                        Description   = forum.Description,
                        ForumImageUrl = forum.ImageUrl
                    };

                    return(View(model));
                }
            }

            return(RedirectToAction("Index", "Forum"));
        }