示例#1
0
        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));
        }
示例#2
0
        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)));
        }
示例#5
0
        //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)));
        }
示例#8
0
        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)));
        }
示例#9
0
        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));
        }
示例#11
0
        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));
        }
示例#12
0
        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)));
        }
示例#13
0
        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)));
        }
示例#16
0
        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)));
        }
示例#17
0
        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()));
        }
示例#18
0
        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)));
        }
示例#19
0
        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)));
        }
示例#20
0
        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));
        }
示例#21
0
        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));
        }
示例#22
0
        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)));
        }
示例#23
0
        //
        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)));
        }
示例#24
0
        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)));
        }
示例#25
0
        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));
        }