public CommentConfirmationDto Create(CommentCreateDto dto)
        {
            User user = MockedData.Users.FirstOrDefault(e => e.Id == dto.UserId);

            if (user == null)
            {
                throw new BusinessException("User does not exit");
            }

            Post post = MockedData.Posts.FirstOrDefault(e => e.Id == dto.UserId);

            if (post == null)
            {
                throw new BusinessException("Post does not exit");
            }

            Comment comment = new Comment()
            {
                Id        = Guid.NewGuid(),
                Content   = dto.Content,
                CreatedAt = DateTime.UtcNow,
                UserId    = dto.UserId,
                PosId     = dto.PosId
            };

            _context.Comments.Add(comment);
            _context.SaveChanges();

            _logger.Log("Comment created");

            return(_mapper.Map <CommentConfirmationDto>(comment));
        }
        public PostRateConfirmationDto Create(PostRateCreateDto dto)
        {
            Post post = PostMock.Posts.FirstOrDefault(e => e.Id == dto.PostId);

            if (post == null)
            {
                return(null);
            }

            PostRate newRate = new PostRate()
            {
                Id          = Guid.NewGuid(),
                Description = dto.Description,
                RateScale   = dto.RateScale,
                RateTypeId  = dto.RateTypeId,
                PostId      = dto.PostId
            };

            _context.PostRate.Add(newRate);
            _context.SaveChanges();

            _logger.Log("Create PostRate");

            return(_mapper.Map <PostRateConfirmationDto>(newRate));
        }
        public UserRateConfirmationDto Create(UserRateCreateDto dto)
        {
            User transport = UserMock.Users.FirstOrDefault(e => e.Id == dto.UserId);

            if (transport == null)
            {
                return(null);
            }

            UserRate newRate = new UserRate()
            {
                Id          = Guid.NewGuid(),
                Description = dto.Description,
                RateScale   = dto.RateScale,
                RateTypeId  = dto.RateTypeId,
                UserId      = dto.UserId
            };

            _context.UserRate.Add(newRate);
            _context.SaveChanges();

            _logger.Log("Create UserRate");

            return(_mapper.Map <UserRateConfirmationDto>(newRate));
        }
Exemple #4
0
        public ActionResult <BlockReadDto> Create(BlockCreateDto blockCreateDto)
        {
            User blockerUser = _userService.Get(blockCreateDto.BlockerId);

            if (blockerUser == null)
            {
                return(BadRequest("Blocker user doesn't exist"));
            }

            User blockedUser = _userService.Get(blockCreateDto.BlockedId);

            if (blockedUser == null)
            {
                return(BadRequest("Blocked user doesn't exist"));
            }

            if (blockCreateDto.BlockerId == blockCreateDto.BlockedId)
            {
                return(BadRequest("BlockedId and BlockerIds cannot be the same"));
            }

            Block block = _blockRepository.Get(blockCreateDto.BlockerId, blockCreateDto.BlockedId);

            if (block != null)
            {
                return(BadRequest("This block already exists"));
            }

            block = _mapper.Map <Block>(blockCreateDto);
            block.CreateDateTime = DateTime.UtcNow;
            _blockRepository.Create(block);
            _logger.Log("Create a Block");

            return(Ok(block));
        }
Exemple #5
0
        public MessageConfirmationDto Create(MessageCreateDto dto)
        {
            User sender = UserData.Users.FirstOrDefault(e => e.Id == dto.SenderId);

            if (sender == null)
            {
                throw new Exception("User does not exit");
            }

            User reciver = UserData.Users.FirstOrDefault(e => e.Id == dto.ReciverId);

            if (reciver == null)
            {
                throw new Exception("User does not exit");
            }

            Message message = new Message()
            {
                Id        = Guid.NewGuid(),
                Content   = dto.Content,
                IsSeen    = dto.IsSeen,
                ReciverId = dto.ReciverId,
                SenderId  = dto.SenderId
            };

            _context.Messages.Add(message);
            _context.SaveChanges();

            _logger.Log("Message created");

            return(_mapper.Map <MessageConfirmationDto>(message));
        }
Exemple #6
0
        public TransportRateConfirmationDto Create(TransportRateCreateDto dto)
        {
            Transport transport = TransportMock.Transports.FirstOrDefault(e => e.Id == dto.TransportId);

            if (transport == null)
            {
                return(null);
            }

            TransportRate newRate = new TransportRate()
            {
                Id          = Guid.NewGuid(),
                Description = dto.Description,
                RateScale   = dto.RateScale,
                RateTypeId  = dto.RateTypeId,
                TransportId = dto.TransportId
            };

            _context.TransportRate.Add(newRate);
            _context.SaveChanges();

            _logger.Log("Create TransportRate");

            return(_mapper.Map <TransportRateConfirmationDto>(newRate));
        }
Exemple #7
0
        public void ForEach_ThrowsArgumentNullException_WhenSourceIsNull()
        {
            // Arrange
            IEnumerable <string> words = null;

            // Act
            // Assert
            Assert.Throws <ArgumentNullException>(() => words.ForEach(word => _fakeLogger.Log(word)));
        }
Exemple #8
0
        public async Task WhenRequestNullThenDoNotCallVisitService()
        {
            var service = new Neo4JService(settings, client, logger);
            await service.InsertNewRequest(null);

            A.CallTo(() => logger.Log(LogLevel.Warning, A <Exception> .Ignored, A <string> .Ignored))
            .MustHaveHappened(1, Times.Exactly);
            A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).MustNotHaveHappened();
        }
        public ActionResult <CurrencyReadDto> Create(CurrencyCreateDto currencyCreateDto)
        {
            Currency currency = _mapper.Map <Currency>(currencyCreateDto);

            currency.CreatedAt = DateTime.UtcNow;

            _currencyRepository.Create(currency);

            _logger.Log("Create Currency");

            return(Ok(currency));
        }
Exemple #10
0
        public RateTypeConfirmationDto Create(RateTypeCreateDto dto)
        {
            RateType rateType = new RateType()
            {
                Id           = Guid.NewGuid(),
                RateTypeName = dto.RateTypeName
            };

            _context.RateTypes.Add(rateType);
            _context.SaveChanges();

            _logger.Log("Create RateType");

            return(_mapper.Map <RateTypeConfirmationDto>(rateType));
        }
        public ActionResult <AccountReadDto> Create([FromBody] AccountCreateDto accountCreateDto)
        {
            var user = _userRepository.Get(accountCreateDto.UserId);

            if (user == null)
            {
                return(BadRequest("User with that id doesn't exist."));
            }

            Account account = _mapper.Map <Account>(accountCreateDto);

            account.CreatedAt = DateTime.UtcNow;

            Currency currency = _currencyRepository.Get(account.CurrencyId);

            if (currency == null)
            {
                return(BadRequest("Currency with that id doesn't exist."));
            }

            _accountRepository.Create(account);

            _logger.Log("Create Account");

            return(Ok(_mapper.Map <AccountReadDto>(account)));
        }
Exemple #12
0
        public ActionResult <string> Login(LoginDto dto)
        {
            User user = _userRepository.Get(dto.Email);

            if (user == null || user.Password != dto.Password)
            {
                return(BadRequest("Email or password incorrect"));
            }

            string token = GenerateJwtToken(user);

            _logger.Log("Login");

            return(Ok(token));
        }
Exemple #13
0
        public ActionResult <LikeReadDto> Create([FromBody] LikeCreateDto likeCreateDto)
        {
            Account account = _accountRepository.Get(likeCreateDto.AccountUid);

            if (account == null)
            {
                return(BadRequest("Account doesnt exist"));
            }
            Like like = _mapper.Map <Like>(likeCreateDto);

            _likeRepository.Create(like);
            _logger.Log("Like created");
            return(Ok(_mapper.Map <LikeReadDto>(like)));
        }
Exemple #14
0
        public ActionResult <CommentReadDto> Create([FromBody] CommentCreateDto commentCreateDto)
        {
            var account = _accountRepository.Get(commentCreateDto.AccountUid);

            if (account == null)
            {
                return(BadRequest("Account not found"));
            }

            Comment comment = _mapper.Map <Comment>(commentCreateDto);

            comment.TimeAndDate = DateTime.UtcNow;
            _commentRepository.Create(comment);
            _logger.Log("Comment created");
            return(Ok(_mapper.Map <CommentReadDto>(comment)));
        }