Ejemplo n.º 1
0
        public void AddLike(AddLikeDto like)
        {
            var addLike = new Likes();

            var existingLike = _likesRepository.GetFirstWhere(x => x.UserId == like.UserId && x.PostId == like.PostId);

            if (existingLike != null)
            {
                throw new FlowException("Like already exists!");
            }

            addLike = DTOtoModel.AddLikeDTOtoLike(like, addLike);
            _likesRepository.Add(addLike);
            _likesRepository.SaveEntities();
        }
Ejemplo n.º 2
0
        public Posts AddPost(PostDto postDto)
        {
            if (postDto.PhotoUploaded.Length == 0)
            {
                throw new FlowException("Please choose photo!");
            }
            else if (postDto.Description.Length > 100)
            {
                throw new FlowException("Description length must be max 100 chars!");
            }

            var post = DTOtoModel.PostDTOtoPost(postDto);

            _postsRepository.Add(post);
            _postsRepository.SaveEntities();

            return(post);
        }
Ejemplo n.º 3
0
        public void RegisterUser(RegisterUserDto user)
        {
            var existingUser = _usersRepository.GetFirstWhere(x => x.Email.ToLower().Trim() == user.Email.ToLower().Trim());

            if (existingUser != null)
            {
                throw new FlowException("User with this e-mail already exists!");
            }

            ValidateEmail(user);
            ValidateBirthday(user);
            ValidatePassword(user);

            var newUser = DTOtoModel.DtoToUserRegistration(user);

            _usersRepository.Add(newUser);
            _usersRepository.SaveEntities();
        }
Ejemplo n.º 4
0
        public AddCommentDto AddComment(AddCommentDto comment)
        {
            var addComment = new Comments();

            if (comment.Comment.Length == 0)
            {
                throw new FlowException("Please insert comment!");
            }
            else if (comment.Comment.Length > 100)
            {
                throw new FlowException("Length must be lower than 100chars!");
            }

            addComment = DTOtoModel.AddCommentDTOtoComment(comment, addComment);
            _commentsRepository.Add(addComment);
            _commentsRepository.SaveEntities();

            return(comment);
        }