예제 #1
0
        public async Task <UserRegisterResponse> Register(UserRegisterRequest data)
        {
            UserRegisterResponse userRegisterResponse;

            var user = await _userEfRepository.GetAsync(data.Email);

            if (user != null)
            {
                userRegisterResponse = _userCreator.CreateUserRegistered(user);
                userRegisterResponse.Failed(_errorService.GetError(ErrorType.UserAlreadyExists));

                return(userRegisterResponse);
            }

            user = _userCreator.CreateUser(data);

            await _userEfRepository.InsertAsync(user);

            await _userEfRepository.SaveChangesAsync();

            userRegisterResponse = _userCreator.CreateUserRegistered(user);
            userRegisterResponse.Succeeded();

            return(userRegisterResponse);
        }
예제 #2
0
        public IActionResult Index()
        {
            IExceptionHandlerPathFeature feature = HttpContext.Features.Get <IExceptionHandlerPathFeature>();
            ErrorViewModel error = errorService.GetError(feature.Error);

            return(View(error));
        }
예제 #3
0
        public async Task <ReturnValues <bool> > Follow(string userId, string userToFollowId)
        {
            if (!await UsersExists(userId, userToFollowId))
            {
                return(new ReturnValues <bool>(_errorService.GetError(Error.UserDosentExist)));
            }

            if (await UserAlreadyFollowed(userId, userToFollowId))
            {
                return(new ReturnValues <bool>(_errorService.GetError(Error.UserIsAlreadyFollowed)));
            }

            await _context.AddAsync(new Follow(userId, userToFollowId));

            await _context.SaveChangesAsync();

            return(new ReturnValues <bool>());
        }
예제 #4
0
        public async Task <ReturnValues <bool> > CreatePost(string userId, PostDto postDto)
        {
            if (!await IsUserExist(userId))
            {
                return(new ReturnValues <bool>(_errorService.GetError(Error.UserDosentExist)));
            }

            if (!IsPostDtoValid(postDto))
            {
                return(new ReturnValues <bool>(_errorService.GetError(Error.PostDtoNotFilled)));
            }

            var post = GetEntityPost(userId, postDto);

            await _context.Posts.AddAsync(post);

            await _context.SaveChangesAsync();

            return(new ReturnValues <bool>(true));
        }
예제 #5
0
        public async Task <ReturnValues <bool> > SendQuestion(string senderId, string receiverId, string message)
        {
            var usersExist = await _context.CustomUsers.CountAsync(x => x.Id == senderId || x.Id == receiverId);

            if (usersExist != 2)
            {
                return(new ReturnValues <bool>(_errorService.GetError(Error.UserDosentExist)));
            }

            if (string.IsNullOrEmpty(message))
            {
                return(new ReturnValues <bool>(_errorService.GetError(Error.EmptyMessage)));
            }

            var question = new Question(senderId, receiverId, message);

            await _context.AddAsync(question);

            await _context.SaveChangesAsync();

            return(new ReturnValues <bool>());
        }
예제 #6
0
        public async Task GetPosts_Return_Error_When_User_Wasnot_Provide()
        {
            //Arrange

            //Act
            var result = await _postService.GetPosts(null);

            //Arrange
            Assert.False(result.Succeeded);
            Assert.AreEqual(_errorService.GetError(Error.UserDosentExist), result.ErrorMessage);
        }
예제 #7
0
        public async Task Follow_Should_Return_Error_When_UserToFollow_Doesnt_Exist()
        {
            // Arange

            // Act
            var result = await _followService.Follow(_userId, _wrongUserId);

            // Assert
            Assert.False(result.Succeeded);
            Assert.AreEqual(_errorService.GetError(Error.UserDosentExist), result.ErrorMessage);
        }
예제 #8
0
        public async Task <BoardUpdateResponse> BoardUpdate(BoardUpdateRequest request)
        {
            BoardUpdateResponse response;

            var board = await _boardRepository.GetAsync(request.Id);

            if (board == null)
            {
                response = new BoardUpdateResponse {
                    Data = null
                };
                response.Failed(_errorService.GetError(ErrorType.ItemNotFound));

                return(response);
            }

            if (board.CreatedById != request.UserId)
            {
                response = new BoardUpdateResponse {
                    Data = null
                };
                response.Failed(_errorService.GetError(ErrorType.AccessDenied));

                return(response);
            }

            _boardCreator.UpdateBoard(board, request);

            await _boardRepository.UpdateAsync(board);

            response = _boardCreator.CreateBoardUpdateResponse(board);
            response.Succeeded();

            return(response);
        }
        public async Task SendQuestion_Should_Return_Error_When_Message_IsEmptyOrNull(string message)
        {
            // Arrange
            var user = _fakeData.GetUser();
            await _context.AddAsync(user);

            await _context.SaveChangesAsync();

            // Act
            var result = await _qnaService.SendQuestion(_userId, user.Id, message);

            // Assert
            Assert.False(result.Succeeded);
            Assert.AreEqual(_errorService.GetError(Error.EmptyMessage), result.ErrorMessage);
        }