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)); }
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)); }
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)); }
public UserDto GetProfile(int userId) { var user = _usersRepository.FindById(userId); return(Converter.ToDto(user)); }
public UserDto GetUser(string email) => Converter.ToDto(_usersRepository.FindByEmail(email));