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."))); } }
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."))); } }
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."))); } }
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"))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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."))); } }
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.") )); } }
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."))); } }
public async Task <ActionResult <ResultOutDto <IEnumerable <Role> > > > GetRoles() { return(Ok(ResultOutDtoBuilder.Success(await _roleService.GetAll()))); }
public async Task <ActionResult <ResultOutDto <IEnumerable <Application> > > > GetApplications( [FromQuery] ApplicationFilterInDto filterOptions) { return(Ok(ResultOutDtoBuilder .Success(await _applicationService.Filter(filterOptions)))); }
public async Task <ActionResult <ResultOutDto <IEnumerable <User> > > > GetUsers([FromQuery] UserFilterInDto filterOptions) { var filteredUsers = await _userService.Filter(filterOptions); return(Ok(ResultOutDtoBuilder.Success(filteredUsers))); }
public async Task <ActionResult <ResultOutDto <List <GroupCountOutDto <int?> > > > > GroupCount() { return(Ok(ResultOutDtoBuilder.Success(await _categoryService.Group()))); }
public async Task <ActionResult <ResultOutDto <IEnumerable <CommentCategory> > > > GetCommentCategories() { return(Ok(ResultOutDtoBuilder.Success(await _categoryService.GetAll()))); }
public async Task <ActionResult <ResultOutDto <List <Post> > > > GetPosts([FromQuery] PostFilterInDto filterOptions) { return(Ok(ResultOutDtoBuilder.Success(await _postService.Filter(filterOptions)))); }
public async Task <ActionResult <ResultOutDto <IEnumerable <Comment> > > > GetComments([FromQuery] CommentFilterInDto filterOptions) { return(Ok(ResultOutDtoBuilder .Success(await _commentService.Filter(filterOptions)))); }
public async Task <ActionResult <ResultOutDto <IEnumerable <Permission> > > > GetPermissions() { return(Ok(ResultOutDtoBuilder.Success(await _permissionService.GetAll()))); }
public async Task <ActionResult <ResultOutDto <IEnumerable <PostStatus> > > > GetPostStatuses() { return(Ok(ResultOutDtoBuilder.Success(await _statusService.GetAll()))); }
public async Task <ActionResult <ResultOutDto <IEnumerable <PostTag> > > > GetPostTags() { return(Ok(ResultOutDtoBuilder.Success(await _postTagService.GetAll()))); }