示例#1
0
        public async Task <ActionResult <ResultOutDto <object> > > DeleteUserRole([FromRoute] string userId, [FromRoute] int roleId)
        {
            if (Guid.TryParse(userId, out Guid guid))
            {
                return(BadRequest(ResultOutDtoBuilder
                                  .Fail <object>(new FormatException(), "Error user id format.")));
            }

            try
            {
                await _roleService.RemoveRolePlayer(guid, roleId);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder
                                .Fail <object>(e, "Not exist.")));
            }
            catch (LeastOneAdminConflictException e)
            {
                return(Conflict(ResultOutDtoBuilder
                                .Fail <object>(e, "At least one admin.")));
            }
        }
示例#2
0
        public async Task <ActionResult <ResultOutDto <User> > > DeleteUser(string id)
        {
            if (!Guid.TryParse(id, out Guid guid))
            {
                return(BadRequest(ResultOutDtoBuilder.Fail <User>(new FormatException(), "Error id format")));
            }
            try
            {
                await _userService.Remove(guid);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(
                           ResultOutDtoBuilder.Fail <User>(
                               e, "Not found the user.")));
            }
            catch (LeastOneAdminConflictException e)
            {
                return(Conflict(
                           ResultOutDtoBuilder.Fail <User>(
                               e, "Can not delete, should at lease have one admin."
                               )));
            }
        }
 public async Task <ActionResult <ResultOutDto <PostCategory> > > PostPostCategory(
     [FromBody] TagCreateInDto createOptions)
 {
     try
     {
         return(Ok(ResultOutDtoBuilder.Success(await _categoryService.Create(createOptions))));
     }
     catch (ExistedConflictException e)
     {
         return(Conflict(ResultOutDtoBuilder.Fail <PostCategory>(e, "Category name existed.")));
     }
 }
示例#4
0
        public async Task <ActionResult <ResultOutDto <Permission> > > GetPermission(int id)
        {
            try
            {
                var permission = await _permissionService.Get(id);

                return(Ok(ResultOutDtoBuilder.Success(permission)));
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder.Fail <Permission>(e, "Not exist.")));
            }
        }
示例#5
0
        public async Task <ActionResult <ResultOutDto <Post> > > PostPost([FromBody] PostCreateInDto createOptions)
        {
            try
            {
                var post = await _postService.Create(createOptions);

                return(Ok(ResultOutDtoBuilder.Success(post)));
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder.Fail <Post>(e, "Not exist")));
            }
        }
示例#6
0
        public async Task <ActionResult <ResultOutDto <User> > > PostUser([FromBody] UserCreateInDto createOptions)
        {
            try
            {
                var user = await _userService.Create(createOptions);

                return(Ok(ResultOutDtoBuilder.Success(user)));
            }
            catch (ExistedConflictException e)
            {
                return(Conflict(ResultOutDtoBuilder.Fail <User>(e, "New name conflict with other existed user.")));
            }
        }
示例#7
0
        public async Task <ActionResult <ResultOutDto <Comment> > > PostComment([FromBody] CommentCreateInDto createOptions)
        {
            try
            {
                var comment = await _commentService.Create(createOptions);

                return(Ok(ResultOutDtoBuilder.Success(comment)));
            }
            catch (NotExistedException e)
            {
                return(BadRequest(ResultOutDtoBuilder.Fail <Comment>(e, "No that post.")));
            }
        }
示例#8
0
        public async Task <ActionResult <ResultOutDto <Role> > > GetRole(int id)
        {
            try
            {
                var role = await _roleService.Get(id);

                return(Ok(ResultOutDtoBuilder.Success(role)));
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder.Fail <Role>(e, "Not exist.")));
            }
        }
        public async Task <ActionResult <ResultOutDto <object> > > DeletePostCategory(
            [FromRoute] int id)
        {
            try
            {
                await _categoryService.Remove(id);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder.Fail <object>(e, "Not exist.")));
            }
        }
示例#10
0
        public async Task <ActionResult <ResultOutDto <UserRoleAssociation> > > PostUserRole([FromBody] UserRoleCreateInDto options)
        {
            try
            {
                var res = await _roleService.AddRolePlayer(options.UserId, options.RoleId);

                return(Ok(ResultOutDtoBuilder.Success(res)));
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder
                                .Fail <UserRoleAssociation>(e, "Not exist.")));
            }
        }
示例#11
0
        public async Task <ActionResult <ResultOutDto <Application> > > PostApplication(ApplicationCreateInDto createOptions)
        {
            try
            {
                var applications = await _applicationService.Create(createOptions);

                return(Ok(ResultOutDtoBuilder.Success(applications)));
            }
            catch (ExistedConflictException e)
            {
                return(Conflict(
                           ResultOutDtoBuilder.Fail <Application>(e, "New name conflict with other existed application.")));
            }
        }
示例#12
0
        public async Task <ActionResult <ResultOutDto <Post> > > GetPost([FromRoute] string id)
        {
            if (!Guid.TryParse(id, out Guid guid))
            {
                return(BadRequest(ResultOutDtoBuilder
                                  .Fail <Post>(new FormatException(), "Error guid id format.")));
            }

            try
            {
                return(Ok(ResultOutDtoBuilder.Success(await _postService.Get(guid))));
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder
                                .Fail <Post>(e, "Not exist.")));
            }
        }
示例#13
0
        public async Task <ActionResult <ResultOutDto <object> > > DeleteComment([FromRoute] string id)
        {
            if (!Guid.TryParse(id, out Guid guid))
            {
                return(BadRequest(ResultOutDtoBuilder
                                  .Fail <Comment>(new FormatException(), "Error guid format.")));
            }
            try
            {
                await _commentService.Remove(guid);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder
                                .Fail <Comment>(e, "Not exist.")));
            }
        }
示例#14
0
        public async Task <ActionResult <ResultOutDto <User> > > GetUser(string id)
        {
            if (!Guid.TryParse(id, out Guid guid))
            {
                return(BadRequest(ResultOutDtoBuilder.Fail <User>(new FormatException(), "Error id format")));
            }
            try
            {
                var user = await _userService.Get(guid, true);

                return(Ok(ResultOutDtoBuilder.Success(user)));
            }
            catch (NotExistedException e)
            {
                return(NotFound(
                           ResultOutDtoBuilder.Fail <User>(
                               e, "Not found the user.")));
            }
        }
示例#15
0
        public async Task <ActionResult <ResultOutDto <object> > > PutPost([FromRoute] string id, [FromBody] Post post)
        {
            if (!Guid.TryParse(id, out Guid guid) || guid != post.Id)
            {
                return(BadRequest(ResultOutDtoBuilder
                                  .Fail <Post>(new FormatException(), "Error id format.")));
            }

            try
            {
                await _postService.Update(post);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder
                                .Fail <Post>(e, "Not exist.")));
            }
        }
示例#16
0
        public async Task <ActionResult <ResultOutDto <Application> > > GetApplication(string id)
        {
            if (!Guid.TryParse(id, out Guid guid))
            {
                return(BadRequest(ResultOutDtoBuilder
                                  .Fail <Application>(new FormatException(), "Error guid format.")));
            }

            try
            {
                var application = await _applicationService.Get(guid, true);

                return(Ok(ResultOutDtoBuilder.Success(application)));
            }
            catch (NotExistedException e)
            {
                return(NotFound(
                           ResultOutDtoBuilder.Fail <Application>(
                               e, "Not exist.")));
            }
        }
示例#17
0
        public async Task <ActionResult <ResultOutDto <User> > > PutUser(string id, User user)
        {
            if (Guid.TryParse(id, out Guid guid) || guid != user.Id)
            {
                return(BadRequest(ResultOutDtoBuilder.Fail <User>(new FormatException(), "Error id format")));
            }

            try
            {
                await _userService.Update(user);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder.Fail <User>(e, "Not exist.")));
            }
            catch (ExistedConflictException e)
            {
                return(Conflict(ResultOutDtoBuilder.Fail <User>(e, "New name conflict with other existed user.")));
            }
        }
示例#18
0
        public async Task <ActionResult <ResultOutDto <object> > > PutApplication(string id, Application application)
        {
            if (!Guid.TryParse(id, out Guid guid) || guid != application.Id)
            {
                return(BadRequest(ResultOutDtoBuilder.Fail <User>(new FormatException(), "Error id format")));
            }

            try
            {
                await _applicationService.Update(application);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder.Fail <Application>(e, "Not exist.")));
            }
            catch (ExistedConflictException e)
            {
                return(Conflict(
                           ResultOutDtoBuilder.Fail <Application>(e, "New name conflict with other existed application.")));
            }
        }
示例#19
0
        public async Task <ActionResult <ResultOutDto <object> > > CreateSession([FromBody] SessionCreateInDto createOptions)
        {
            try
            {
                var token = await _userService.Login(createOptions);

                return(Ok(ResultOutDtoBuilder.Success(token)));
            }
            catch (NotExistedException e)
            {
                return(NotFound(
                           ResultOutDtoBuilder
                           .Fail <object>(e, "Target user not exist.")
                           ));
            }
            catch (BadAuthenticationException e)
            {
                return(Unauthorized(
                           ResultOutDtoBuilder
                           .Fail <object>(e, "User name and password don't match.")
                           ));
            }
        }
示例#20
0
        public async Task <ActionResult <ResultOutDto <object> > > PutPostCategories(
            [FromRoute] int id, [FromBody] PostCategory category
            )
        {
            if (id != category.Id)
            {
                return(BadRequest(ResultOutDtoBuilder.Fail <object>(new FormatException(), "error id format")));
            }

            try
            {
                await _categoryService.Update(category);

                return(NoContent());
            }
            catch (NotExistedException e)
            {
                return(NotFound(ResultOutDtoBuilder.Fail <object>(e, "Not exist.")));
            }
            catch (ExistedConflictException e)
            {
                return(Conflict(ResultOutDtoBuilder.Fail <object>(e, "Conflict name.")));
            }
        }
示例#21
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <Role> > > > GetRoles()
 {
     return(Ok(ResultOutDtoBuilder.Success(await _roleService.GetAll())));
 }
示例#22
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <Application> > > > GetApplications(
     [FromQuery] ApplicationFilterInDto filterOptions)
 {
     return(Ok(ResultOutDtoBuilder
               .Success(await _applicationService.Filter(filterOptions))));
 }
示例#23
0
        public async Task <ActionResult <ResultOutDto <IEnumerable <User> > > > GetUsers([FromQuery] UserFilterInDto filterOptions)
        {
            var filteredUsers = await _userService.Filter(filterOptions);

            return(Ok(ResultOutDtoBuilder.Success(filteredUsers)));
        }
示例#24
0
 public async Task <ActionResult <ResultOutDto <List <GroupCountOutDto <int?> > > > > GroupCount()
 {
     return(Ok(ResultOutDtoBuilder.Success(await _categoryService.Group())));
 }
示例#25
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <CommentCategory> > > > GetCommentCategories()
 {
     return(Ok(ResultOutDtoBuilder.Success(await _categoryService.GetAll())));
 }
示例#26
0
 public async Task <ActionResult <ResultOutDto <List <Post> > > > GetPosts([FromQuery] PostFilterInDto filterOptions)
 {
     return(Ok(ResultOutDtoBuilder.Success(await _postService.Filter(filterOptions))));
 }
示例#27
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <Comment> > > > GetComments([FromQuery] CommentFilterInDto filterOptions)
 {
     return(Ok(ResultOutDtoBuilder
               .Success(await _commentService.Filter(filterOptions))));
 }
示例#28
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <Permission> > > > GetPermissions()
 {
     return(Ok(ResultOutDtoBuilder.Success(await _permissionService.GetAll())));
 }
示例#29
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <PostStatus> > > > GetPostStatuses()
 {
     return(Ok(ResultOutDtoBuilder.Success(await _statusService.GetAll())));
 }
示例#30
0
 public async Task <ActionResult <ResultOutDto <IEnumerable <PostTag> > > > GetPostTags()
 {
     return(Ok(ResultOutDtoBuilder.Success(await _postTagService.GetAll())));
 }