예제 #1
0
        public async Task <IActionResult> AddModerator(int id, [FromBody] string text)
        {
            if (String.IsNullOrEmpty(text))
            {
                return(BadRequest("Field can not be empty."));
            }

            var user = await _accountService.GetUserByUsername(text);

            if (user == null)
            {
                return(NotFound("User is not found."));
            }

            if (user == await _accountService.GetCurrentUser(HttpContext.User))
            {
                return(BadRequest("You already have absolute rights for this blog."));
            }

            if (!_blogService.BlogExists(id))
            {
                return(NotFound());
            }

            if (await _blogService.GetBlogModeratorById(id, user.Id) != null)
            {
                return(BadRequest("This user is already moderator."));
            }

            await _blogService.AddBlogModerator(id, user);

            return(PartialView("~/Views/Blog/_ModeratorsPartial.cshtml", await _blogService.GetAllBlogModerators(id)));
        }