Exemplo n.º 1
0
        public async Task <bool> CheckPostTopicAndParentId(PostCommentData err, ForumContext context)
        {
            if (!int.TryParse(TopicId, out int topicId))
            {
                err.TopicId = "Topic id is incorrect";
                return(false);
            }
            else if (await context.GetTopicById(topicId) == null)
            {
                err.TopicId = "Topic doesn't exist";
                return(false);
            }
            else if (ParentCommentId != null)
            {
                if (!int.TryParse(ParentCommentId, out int parentCommentId))
                {
                    err.ParentCommentId = "Parent comment id is incorrect";
                    return(false);
                }
                else if (await context.GetCommentInTopic(topicId, parentCommentId) == null)
                {
                    err.ParentCommentId = "Comment doesn't exist or doesn't belong to topic";
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> CheckPostData(PostCommentData err, ForumContext context)
        {
            var checkText             = CheckPostText(err);
            var checkTopicAndParentId = await CheckPostTopicAndParentId(err, context);

            return(checkTopicAndParentId && checkText);
        }
Exemplo n.º 3
0
        public async Task <bool> CheckRegEmail(RegData err, ForumContext context)
        {
            if (Email == "")
            {
                err.Email = "Email is required";
                return(false);
            }
            else if (Email.Length >= 50)
            {
                err.Email = "Email is too long";
                return(false);
            }
            else if (!IsValidEmail(Email))
            {
                err.Email = "Email is invalid";
                return(false);
            }
            else if ((await context.GetUserByEmail(Email)) != null)
            {
                err.Email = "Email is already in use";
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public async Task <string> LikeComment(string username, ForumContext context)
        {
            if (!int.TryParse(Id, out int id))
            {
                return("Id is invalid");
            }
            else if (await context.GetCommentById(id) == null)
            {
                return("Comment doesn't exist");
            }

            var like = await context.GetCommentScore(id, username);

            if (like == null)
            {
                await context.LikeComment(id, username);

                return(null);
            }
            else if (like.Score == Score.Dislike)
            {
                await context.DeleteCommentDislike(id, username);

                return(null);
            }
            else
            {
                return("User is already like comment");
            }
        }
Exemplo n.º 5
0
        public async Task <string> DislikeTopic(string username, ForumContext context)
        {
            if (!int.TryParse(Id, out int id))
            {
                return("Id is invalid");
            }
            else if (await context.GetTopicById(id) == null)
            {
                return("Topic doesn't exist");
            }

            var like = await context.GetTopicScore(id, username);

            if (like == null)
            {
                await context.DislikeTopic(id, username);

                return(null);
            }
            else if (like.Score == Score.Like)
            {
                await context.DeleteTopicLike(id, username);

                return(null);
            }
            else
            {
                return("User is already dislike topic");
            }
        }
Exemplo n.º 6
0
        public async Task <bool> CheckRegData(RegData err, ForumContext context)
        {
            var checkUsername = await CheckRegUsername(err, context);

            var checkEmail = await CheckRegEmail(err, context);

            var checkPassword = CheckRegPassword(err);

            return(checkUsername && checkEmail && checkPassword);
        }
Exemplo n.º 7
0
        public async Task <bool> CheckRegUsername(RegData err, ForumContext context)
        {
            if (Username == "")
            {
                err.Username = "******";
                return(false);
            }
            else if (Username.Length >= 20)
            {
                err.Username = "******";
                return(false);
            }
            else if ((await context.GetUserByUsername(Username)) != null)
            {
                err.Username = "******";
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        public async Task <User> CheckLogin(ForumContext context)
        {
            var user = await context.GetUserByUsernameOrEmail(UsernameOrEmail);

            return(user != null && user.ValidatePassword(Password) ? user : null);
        }