public PointService(
     BaseLimits limits,
     IUserRepository userRepository)
 {
     _limits         = limits;
     _userRepository = userRepository;
 }
Exemple #2
0
 public void Edit(string websiteUrl, string aboutMe, BaseLimits limits)
 {
     Validate(websiteUrl, aboutMe, limits);
     WebsiteUrl = string.IsNullOrWhiteSpace(websiteUrl)
         ? null
         : new Uri(websiteUrl);
     AboutMe   = aboutMe;
     CreatedOn = DateTime.UtcNow;
     LastSeen  = DateTime.UtcNow;
 }
Exemple #3
0
 private static void Validate(string websiteUrl, string aboutMe, BaseLimits limits)
 {
     if (!string.IsNullOrWhiteSpace(websiteUrl) && !Uri.TryCreate(websiteUrl, UriKind.Absolute, out var _))
     {
         throw new BusinessException("Website Url is not valid.");
     }
     if (!string.IsNullOrWhiteSpace(aboutMe) && aboutMe.Length > limits.AboutMeMaximumLength)
     {
         throw new BusinessException($"About Me is too long, must be at most {limits.AboutMeMaximumLength} characters.");
     }
 }
 public UserService(
     IUserRepository userRepository,
     IUnitOfWork uow,
     IMapper mapper,
     BaseLimits limits)
 {
     _userRepository = userRepository;
     _uow            = uow;
     _mapper         = mapper;
     _limits         = limits;
 }
Exemple #5
0
 public void RevokeVote(Vote vote, BaseLimits limits)
 {
     if (_votes.SingleOrDefault(v => v.UserId == vote.UserId) == null)
     {
         throw new BusinessException($"Vote does not exist on {vote.Target.Name} '{vote.TargetId}'.");
     }
     if (vote.CreatedOn.Add(limits.VoteEditDeadline) < DateTime.UtcNow)
     {
         throw new BusinessException($"{vote.Target.Name} with id '{vote.TargetId}' cannot be edited since more than '{limits.AnswerEditDeadline.Minutes}' minutes passed.");
     }
     // @nl: Tell (q/a/c) target owner that they received an upvote/downvote (use inbox).
     // @nl: initiate point recalculation for (q/a/c) target owner.
 }
Exemple #6
0
 public QuestionUpdateRequestValidator(BaseLimits limits)
 {
     RuleFor(x => x.Body)
     .MinimumLength(limits.QuestionBodyMinimumLength)
     .WithMessage($"Question's body must be at least {limits.QuestionBodyMinimumLength} characters.");
     RuleFor(x => x.TagIds)
     .Must(t =>
     {
         var count = t.Count();
         return(count >= limits.TagMinimumCount && count <= limits.TagMaximumCount);
     })
     .WithMessage($"Question must be tagged with {limits.TagMinimumCount} to {limits.TagMaximumCount} tags.");
 }
Exemple #7
0
        /// <summary>
        /// Provide Id based on token service's user identifier.
        /// </summary>
        public static User Create(BaseLimits limits, Guid id, string username, string email = null, string websiteUrl = null, string aboutMe = null)
        {
            Validate(websiteUrl, aboutMe, limits);
            User user = new User();

            user.Id         = id;
            user.Username   = username;
            user.Email      = email;
            user.WebsiteUrl = string.IsNullOrWhiteSpace(websiteUrl)
                ? null
                : new Uri(websiteUrl);
            user.AboutMe   = aboutMe;
            user.CreatedOn = DateTime.UtcNow;
            user.SeenNow();
            user.AssignRole(Role.User);
            return(user);
        }
 public VoteService(IVoteRepository voteRepository,
                    IRepository <Question> questionRepository,
                    IRepository <Answer> answerRepository,
                    IRepository <Comment> commentRepository,
                    IUnitOfWork uow,
                    BaseLimits limits,
                    IEventRegister eventRegister,
                    ICache cache,
                    IMapper mapper)
 {
     _voteRepository     = voteRepository;
     _questionRepository = questionRepository;
     _answerRepository   = answerRepository;
     _commentRepository  = commentRepository;
     _uow           = uow;
     _limits        = limits;
     _eventRegister = eventRegister;
     _cache         = cache;
     _mapper        = mapper;
 }
 public CommentService(IQuestionRepository questionRepository,
                       ICommentRepository commentRepository,
                       IAnswerRepository answerRepository,
                       IUserRepository userRepository,
                       ICache cache,
                       IRepository <Vote> voteRepository,
                       IUnitOfWork unitOfWork,
                       BaseLimits limits,
                       IMapper mapper)
 {
     _questionRepository = questionRepository;
     _answerRepository   = answerRepository;
     _commentRepository  = commentRepository;
     _userRepository     = userRepository;
     _cache          = cache;
     _voteRepository = voteRepository;
     _uow            = unitOfWork;
     _limits         = limits;
     _voteable       = new Voteable();
     _mapper         = mapper;
 }
 public QuestionService(
     IQuestionRepository questionRepository,
     IUserRepository userRepository,
     IUnitOfWork uow,
     ICommentService commentService,
     ICache cache,
     IVoteRepository voteRepository,
     IVoteService voteService,
     ITagService tagService,
     BaseLimits limits,
     IMapper mapper)
 {
     _questionRepository = questionRepository;
     _userRepository     = userRepository;
     _uow            = uow;
     _commentService = commentService;
     _cache          = cache;
     _voteRepository = voteRepository;
     _voteService    = voteService;
     _tagService     = tagService;
     _limits         = limits;
     _mapper         = mapper;
 }
 public UpdateCommentRequestValidator(BaseLimits limits)
 {
     RuleFor(x => x.Body)
     .MinimumLength(limits.CommentBodyMinimumLength)
     .WithMessage($"Comment's body must be at least {limits.CommentBodyMinimumLength} characters.");
 }