public async Task <IActionResult> Put([FromBody] PredictionDto dto)
        {
            var prediction = _mapper.Map <Prediction>(dto);
            await _predictionService.UpdateAsync(prediction);

            return(Ok("Updated"));
        }
        public async Task <IActionResult> Post([FromBody] PredictionDto dto)
        {
            var prediction = _mapper.Map <Prediction>(dto);
            await _predictionService.AddAsync(prediction);

            return(Created("localhost", ""));
        }
Exemplo n.º 3
0
        public async Task <int> CompareResultsAsync(GameDto game, PredictionDto prediction)
        {
            var gameEntity       = game.ToEntity();
            var predictionEntity = prediction.ToEntity();
            var test             = await _predictionRepository.CompareResultsAsync(gameEntity, predictionEntity);

            return(test);
        }
Exemplo n.º 4
0
 public async Task Update(int id, [FromBody] PredictionDto prediction)
 {
     prediction.Id = id;
     var request = new UpdatePredictionRequest
     {
         Prediction = prediction
     };
     await _mediator.ExecuteAsync(request).ConfigureAwait(false);
 }
Exemplo n.º 5
0
        public async Task <HttpResponseMessage> Create([FromBody] PredictionDto prediction)
        {
            var request = new CreatePredictionRequest
            {
                Prediction = prediction
            };
            await _mediator.ExecuteAsync(request).ConfigureAwait(false);

            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Exemplo n.º 6
0
        public void InsertPredictionToDbTest()
        {
            PredictionDto prediction = new PredictionDto();

            prediction.PredictionText = "Hello!";

            IPredictionsRepository repository = new PredictionsDb();

            repository.InsertPrediction(prediction);
        }
Exemplo n.º 7
0
        public void Test1()
        {
            PredictionDto predDto = new PredictionDto()
            {
                PredictionText = "yesno 2"
            };

            IPredictionsRepository predictionsRepository = new PredictionsDatabaseRepository();

            predictionsRepository.SavePrediction(predDto.PredictionText);
        }
        public IHttpActionResult Save(PredictionDto prediction)
        {
            var repo = new Repository();

            repo.SavePrediction(
                User.Identity.Name,
                prediction.MatchId,
                prediction.HomeGoals,
                prediction.AwayGoals);

            return(Ok());
        }
Exemplo n.º 9
0
        public async Task UpdatePredictionAsync(int gameId, Guid?userId, string prediction)
        {
            PredictionDto predictionDto = new PredictionDto()
            {
                GameId          = gameId,
                UserId          = userId,
                PredictedResult = prediction
            };

            var predictionEntity = predictionDto.ToEntity();

            await _predictionRepository.UpdatePredictionAsync(predictionEntity);
        }
Exemplo n.º 10
0
        public async Task CompareResultsAsyncTest1()
        {
            //Arrange
            //await CreateNewDbInstance();
            await CreateDb();

            GameDto game = new GameDto();

            game.Result = "2-2";
            PredictionDto prediction = new PredictionDto();

            prediction.PredictedResult = "1-1";

            //Act
            var points = await _predictionService2.CompareResultsAsync(game, prediction);

            //Assert
            Assert.AreEqual(1, points);
        }
Exemplo n.º 11
0
        public void Test3()
        {
            IPredictionsRepository predictionsRepository = new PredictionsDatabaseRepository();
            PredictionDto          oldPred = new PredictionDto()
            {
                PredictionText = predictionsRepository.GetPredictionById(2)
            };

            predictionsRepository.UpdatePrediction(oldPred, new PredictionDto()
            {
                PredictionText = oldPred.PredictionText + "test"
            });
            Assert.Throws <Exception>((() => {
                if (predictionsRepository.GetPredictionById(2) != oldPred.PredictionText)
                {
                    throw new Exception();
                }
            }));
        }
Exemplo n.º 12
0
        public async Task CompareResultsAsyncTest2()
        {
            //Arrange
            //await CreateNewDbInstance();
            await CreateDb();

            GameDto game = new GameDto();

            game.Result     = "0-2";
            game.typeResult = await _predictionService2.CheckTypeResult(game.Result);

            PredictionDto prediction = new PredictionDto();

            prediction.PredictedResult     = "3-0";
            prediction.PredictedTypeResult = await _predictionService2.CheckTypeResult(prediction.PredictedResult);

            //Act
            var points = await _predictionService2.CompareResultsAsync(game, prediction);

            //Assert
            Assert.AreEqual(0, points);
        }
Exemplo n.º 13
0
        public async Task AddPointsAsync(Guid?userId, int gameId, int points)
        {
            var prediction = await _predictionRepository.GetPredictionAsync(gameId, userId);

            if (prediction != null)
            {
                prediction.EarnedPoints = points;
            }
            else
            {
                PredictionDto predictionDto = new PredictionDto()
                {
                    GameId       = gameId,
                    UserId       = userId,
                    EarnedPoints = points
                };

                prediction = predictionDto.ToEntity();
            }

            await _predictionRepository.AddPointsAsync(prediction);
        }
Exemplo n.º 14
0
 public static Prediction ToEntity(this PredictionDto prediction)
 {
     return(prediction == null ? null : Mapper.Map <Prediction>(prediction));
 }
Exemplo n.º 15
0
 public Prediction(PredictionDto dto)
 {
     PredictionText = dto.PredictionText;
     Id             = dto.Id;
 }