示例#1
0
        public PostDto CreatePost(PostDto post, int userId)
        {
            var entity = Converter.ToEntity(post);

            entity.UserId = userId;
            entity.Date   = DateTime.Now;

            _postsRepository.Save(entity);
            return(Converter.ToDto(entity));
        }
示例#2
0
        public CommentReadDto CreateComment(CommentCreateDto commentDto, int postId, int userId)
        {
            var post          = _postsRepository.FindById(postId);
            var commentEntity = Converter.ToEntity(commentDto);

            commentEntity.UserId = userId;
            commentEntity.Date   = DateTime.Now;
            post.Comments.Add(commentEntity);
            _postsRepository.Persist();
            return(Converter.ToDto(commentEntity));
        }
示例#3
0
        public UserDto SignUp(string requestEmail, string requestPassword)
        {
            var userFound = _usersRepository.ExistsByEmail(requestEmail);

            if (userFound)
            {
                throw new BadRequestException("Such user already exists");
            }

            var salt = BCryptHelper.GenerateSalt();
            var user = new User
            {
                Email = requestEmail,
                LastPasswordResetDate = DateTime.Now,
                Password = BCryptHelper.HashPassword(requestPassword, salt),
                Salt     = salt
            };
            var savedUser = _usersRepository.Save(user);

            return(Converter.ToDto(savedUser));
        }
示例#4
0
        public UserDto GetProfile(int userId)
        {
            var user = _usersRepository.FindById(userId);

            return(Converter.ToDto(user));
        }
示例#5
0
 public UserDto GetUser(string email) => Converter.ToDto(_usersRepository.FindByEmail(email));