public async Task <ActionResult> ClaimStudent([FromRoute] int id)
        {
            var response = await _studentRepository.SetMentor(id, _claimProvider.GetUserId());

            if (response.IsError)
            {
                return(BadRequest(response.Message));
            }

            return(Ok());
        }
예제 #2
0
 public UserController(IPostRepository postRepository, INotificationRepository notificationRepository,
                       IClaimProvider claimProvider, IAccessValidator accessValidator)
 {
     _postRepository         = postRepository;
     _notificationRepository = notificationRepository;
     _accessValidator        = accessValidator;
     _userId = claimProvider.GetUserId();
 }
예제 #3
0
        public ShelterController(IAnimalRepository animalRepository, IAdopterRepository adopterRepository,
                                 IShelterRepository shelterRepository, IClaimProvider claimProvider, IAccessValidator accessValidator)
        {
            _animalRepository  = animalRepository;
            _adopterRepository = adopterRepository;
            _shelterRepository = shelterRepository;

            _shelterId       = claimProvider.GetUserId();
            _accessValidator = accessValidator;
        }
        public async Task <ActionResult> PostMessage(SendMessageModel model)
        {
            var response = await _messageRepository.SendMessage(_claimProvider.GetUserId(), model);

            if (response.IsError)
            {
                return(BadRequest(response.Message));
            }

            return(Ok());
        }
        public async Task <UserModel> GetCurrentUserModel()
        {
            var role = _claimProvider.GetUserRole();

            if (role == UserRole.Student)
            {
                var student = await _dbContext.Students
                              .Where(u => u.Id == _claimProvider.GetUserId())
                              .ProjectTo <StudentModel>(_mapper.ConfigurationProvider)
                              .SingleOrDefaultAsync();

                return(student);
            }

            var user = await _dbContext.Users
                       .Where(u => u.Id == _claimProvider.GetUserId())
                       .ProjectTo <UserModel>(_mapper.ConfigurationProvider)
                       .SingleOrDefaultAsync();

            return(user);
        }
예제 #6
0
        public UserModel GetCurrentUserModel()
        {
            var user = _dbContext.Users
                       .Where(u => u.Id == _claimProvider.GetUserId())
                       .Select(u => new UserModel
            {
                Id    = u.Id,
                Email = u.Email,
                Name  = u.Name,
            })
                       .SingleOrDefault();

            return(user);
        }
예제 #7
0
        public async Task <ResponseResult <CommentModel> > Add(CreateCommentModel model, int?userId = null)
        {
            var comment = _mapper.Map <Comment>(model);

            comment.UserId = userId ?? _claimProvider.GetUserId();
            await _context.Comments.AddAsync(comment);

            await _context.SaveChangesAsync();

            var commentModel = await _context
                               .Comments
                               .Where(c => c.Id == comment.Id)
                               .ProjectTo <CommentModel>(_mapper.ConfigurationProvider)
                               .FirstOrDefaultAsync();

            return(new ResponseResult <CommentModel>(commentModel));
        }
예제 #8
0
 public AccessValidator(SaponjaDbContext dbContext, IClaimProvider claimProvider)
 {
     _dbContext = dbContext;
     _userId    = claimProvider.GetUserId();
 }
예제 #9
0
        public async Task <ICollection <MessageModel> > GetPage(int page, int pageSize, int?studentId)
        {
            var baseUrl = _webHostService.GetRootUrl();

            Expression <Func <Message, bool> > userFilterExpression = m =>
                                                                      m.UserFromId == _claimProvider.GetUserId() || m.UserToId == _claimProvider.GetUserId();

            if (studentId.HasValue)
            {
                userFilterExpression = m => m.UserFromId == studentId || m.UserToId == studentId;
            }

            var messages = await _studentMentorDbContext
                           .Messages
                           .Where(userFilterExpression)
                           .OrderByDescending(m => m.MessageCreatedAt)
                           .Skip(page * pageSize)
                           .Take(pageSize)
                           .ProjectTo <MessageModel>(_mapper.ConfigurationProvider, new { baseUrl })
                           .ToListAsync();

            return(messages);
        }
        public async Task <ActionResult> GetMentoringStudents()
        {
            var students = await _studentRepository.GetMentoringStudents(_claimProvider.GetUserId());

            return(Ok(students));
        }