public IDataResult <ChatComment> CreateChatComment(AddChatCommentDto addChatDto) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), CheckReceiverIsExist(addChatDto.ReceiverId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <ChatComment>(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; var chat = GetChatById(user.Id, addChatDto.ReceiverId).Data; if (chat == null) { var result = CreateChatwithComment(user, addChatDto); return(new SuccessDataResult <ChatComment>(GetChatCommentById(result.Data).Data, Message.ChatCommentCreated)); } var chatComment = new ChatComment() { UserId = user.Id, ChatId = chat.Id, Comment = addChatDto.Content }; _uow.ChatComments.Add(chatComment); _uow.Commit(); return(new SuccessDataResult <ChatComment>(GetChatCommentById(chatComment.Id).Data, Message.ChatCommentCreated)); }
public IDataResult <AccessToken> UpdateProfilePicture(IFormFile profilePicture) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), CheckProfilePictureIsEmpty(profilePicture)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <AccessToken>(errorResult)); } var uploadPictureResult = _documentService.UplaodFile(profilePicture, FileType.ProfilePics); if (uploadPictureResult.ResultType != ResultType.Success) { return(ResultConverter.ResultToDataResult <AccessToken>(uploadPictureResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; user.Picture = uploadPictureResult.Message; _uow.Users.Update(user); _uow.Commit(); return(new SuccessDataResult <AccessToken>(_authService.GetAuthenticatedToken(user).Result.Data)); }
public IDataResult <List <ArticleLikeDisslikeDto> > GetUsersLikedOrDisslikedArticle(long articleId, LikeDisslikeType likeDisslikeType) { var errorResult = BusinessRules.Run(IsArticleExist(articleId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <List <ArticleLikeDisslikeDto> >(errorResult)); } return(new SuccessDataResult <List <ArticleLikeDisslikeDto> >(_uow.ArticleLikeDisslikes.GetUsersLikedOrDisslikedArticle(articleId, likeDisslikeType))); }
public IDataResult <TopicCommentDto> GetTopicCommentById(long topicCommentId) { var errorResult = BusinessRules.Run(IsTopicCommentExist(topicCommentId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <TopicCommentDto>(errorResult)); } return(new SuccessDataResult <TopicCommentDto>(_uow.TopicComments.GetTopicCommentById(topicCommentId))); }
//IDSİ GELEN KULLANICI İLE TOKENDAKİ KULLANICININ KONUŞMA GEÇMİŞİ VAR MI ? VAR İSE CHATID DÖN public IDataResult <long> GetChatById(long receiverId) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist()); if (errorResult != null) { return(ResultConverter.ResultToDataResult <long>(errorResult)); } return(new SuccessDataResult <long>(CheckIsChatExistBetweenUsers(_authService.GetAuthenticatedUser().Result.Data.Id, receiverId).Data)); }
public IDataResult <ArticleCategory> GetArticleCategory(long articleCategoryId) { var error = BusinessRules.Run(isArticleCategoryExist(articleCategoryId)); if (error != null) { return(ResultConverter.ResultToDataResult <ArticleCategory>(error)); } return(new SuccessDataResult <ArticleCategory>(_uow.ArticleCategories.Get(x => x.Id == articleCategoryId))); }
public IDataResult <TopicDto> GetTopic(long topicId) { var errorResult = BusinessRules.Run(IsTopicExist(topicId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <TopicDto>(errorResult)); } return(new SuccessDataResult <TopicDto>(this._uow.Topics.GetTopicWithInclude(topicId))); }
public IDataResult <ArticleCommentDto> GetArticleComment(long articleCommentId) { var errorResult = BusinessRules.Run(IsArticleCommentExist(articleCommentId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <ArticleCommentDto>(errorResult)); } return(new SuccessDataResult <ArticleCommentDto>(_uow.ArticleComments.GetArticleById(articleCommentId))); }
public IDataResult <List <ArticleCommentDto> > GetArticleCommentsByUser(long userId) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist()); if (errorResult != null) { return(ResultConverter.ResultToDataResult <List <ArticleCommentDto> >(errorResult)); } return(new SuccessDataResult <List <ArticleCommentDto> >(_uow.ArticleComments.GetArticleCommentsByUser(userId))); }
public IDataResult <PagedList <TopicDto> > GetAllTopics(int currentPage, int pageSize) { var errorResult = BusinessRules.Run(ValidatePagingParams(currentPage, pageSize)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <PagedList <TopicDto> >(errorResult)); } var pagedTopicsList = PagedList <TopicDto> .ToPagedList(_uow.Topics.GetAllTopicsWithInclude(), currentPage, pageSize); return(new SuccessDataResult <PagedList <TopicDto> >(pagedTopicsList)); }
public IDataResult <UserDto> GetUserProfile(long userId) { var errorResult = BusinessRules.Run(CheckUserIsExist(userId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <UserDto>(errorResult)); } var userProfile = _uow.Users.GetUserProfile(userId); return(new SuccessDataResult <UserDto>(userProfile)); }
public IDataResult <List <ChatDto> > GetChatsByUser() { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist()); if (errorResult != null) { return(ResultConverter.ResultToDataResult <List <ChatDto> >(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; return(new SuccessDataResult <List <ChatDto> >(_uow.Chats.GetChatsByUser(user.Id))); }
public IDataResult <PagedList <ArticleDto> > GetMostLikedArticles(int currentPage, int pageSize) { var errorResult = BusinessRules.Run(ValidatePagingParams(currentPage, pageSize)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <PagedList <ArticleDto> >(errorResult)); } var pagedArticleList = PagedList <ArticleDto> .ToPagedList(_uow.Articles.GetMostLikedArticles(), currentPage, pageSize); return(new SuccessDataResult <PagedList <ArticleDto> >(pagedArticleList)); }
public IDataResult <PagedList <TopicCommentDto> > GetTopicCommentsByTopic(long topicId, int currentPage, int pageSize) { var errorResult = BusinessRules.Run(IsTopicExist(topicId), ValidatePagingParams(currentPage, pageSize)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <PagedList <TopicCommentDto> >(errorResult)); } var pagedTopicComments = PagedList <TopicCommentDto> .ToPagedList(_uow.TopicComments.GetTopicCommentsByTopic(topicId), currentPage, pageSize); return(new SuccessDataResult <PagedList <TopicCommentDto> >(pagedTopicComments)); }
public IDataResult <ArticleCategory> PredictArticleCategoryByUser(long userId) { var error = BusinessRules.Run(CheckUserIsExist(userId)); if (error != null) { return(ResultConverter.ResultToDataResult <ArticleCategory>(error)); } var predictedCategoryId = PredictHelper.PredictArticleCategoryByUser(userId); return(new SuccessDataResult <ArticleCategory>(_uow.ArticleCategories.Get(x => x.Id == predictedCategoryId))); }
public IDataResult <List <ChatDto> > GetChatCommentsByChat(long chatId) { var user = _authService.GetAuthenticatedUser().Result.Data; var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), CheckIsChatExist(chatId, user.Id)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <List <ChatDto> >(errorResult)); } return(new SuccessDataResult <List <ChatDto> >(_uow.ChatComments.GetChatCommentsByChat(chatId))); }
public IDataResult <List <Article> > GetArticlesByUser() { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist()); if (errorResult != null) { return(ResultConverter.ResultToDataResult <List <Article> >(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; return(new SuccessDataResult <List <Article> >(_uow.Articles.GetAll(x => x.UserId == user.Id).OrderByDescending(x => x.Created).ToList())); }
public IDataResult <List <AuthorizationAppeal> > GetAuthorizationAppealsByUser() { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist()); if (errorResult != null) { return(ResultConverter.ResultToDataResult <List <AuthorizationAppeal> >(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; return(new SuccessDataResult <List <AuthorizationAppeal> >(this._uow.AuthorizationAppeals.GetAll(x => x.UserId == user.Id))); }
public IDataResult <Article> GetArticleById(long articleId) { var errorResult = BusinessRules.Run(IsArticleExist(articleId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <Article>(errorResult)); } return(new SuccessDataResult <Article>(_uow.Articles.Get(x => x.Id == articleId))); }
public IDataResult <PagedList <ArticleCommentDto> > GetArticleCommentsByArticle(long articleId, int currentPage, int pageSize) { var errorResult = BusinessRules.Run(IsArticleExist(articleId), ValidatePagingParams(currentPage, pageSize)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <PagedList <ArticleCommentDto> >(errorResult)); } var pagedArticleComments = PagedList <ArticleCommentDto> .ToPagedList(_uow.ArticleComments.GetArticleCommentsByArticle(articleId), currentPage, pageSize); return(new SuccessDataResult <PagedList <ArticleCommentDto> >(pagedArticleComments)); }
public IDataResult <PagedList <FavoriteDto> > GetFavoriteArticlesByUser(int currentPage, int pageSize) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), ValidatePagingParams(currentPage, pageSize)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <PagedList <FavoriteDto> >(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; var pagedUserFavorites = PagedList <FavoriteDto> .ToPagedList(_uow.Favorites.GetFavoriteArticlesByUser(user.Id), currentPage, pageSize); return(new SuccessDataResult <PagedList <FavoriteDto> >(pagedUserFavorites)); }
public IDataResult <AuthorizationAppealDto> GetAuthorizationAppealById(long appealId) { var user = _authService.GetAuthenticatedUser().Result.Data; var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), CheckAppealIsExist(appealId), IsAppealBelongToUser(user.Id, appealId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <AuthorizationAppealDto>(errorResult)); } return(new SuccessDataResult <AuthorizationAppealDto>(this._uow.AuthorizationAppeals.GetIncludedAppealById(appealId))); }
// public IDataResult <Article> GetArticleByUser(long articleId) { var user = _authService.GetAuthenticatedUser().Result.Data; var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), IsArticleExist(articleId), IsArticleBelongToUser(user.Id, articleId)); if (errorResult != null) { return(ResultConverter.ResultToDataResult <Article>(errorResult)); } return(new SuccessDataResult <Article>(_uow.Articles.Get(x => x.Id == articleId))); }
public IDataResult <List <ArticleDto> > GetArticlesByUserInterest() { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist()); if (errorResult != null) { return(ResultConverter.ResultToDataResult <List <ArticleDto> >(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; var predictedArticleCategoryId = _articleCategoryService.PredictArticleCategoryByUser(user.Id); return(new SuccessDataResult <List <ArticleDto> >(_uow.Articles.GetArticlesByUserInterest(predictedArticleCategoryId.Data.Id))); }
public IDataResult <AccessToken> UpdateUser(UpdateUserDto updateUserDto) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist()); if (errorResult != null) { return(ResultConverter.ResultToDataResult <AccessToken>(errorResult)); } var user = _authService.GetAuthenticatedUser().Result.Data; user.About = updateUserDto.About; _uow.Users.Update(user); _uow.Commit(); return(new SuccessDataResult <AccessToken>(_authService.GetAuthenticatedToken(user).Result.Data)); }