Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] Game game)
        {
            try {
                await _gameService.AddGameAsync(game);

                return(CreatedAtAction("Post", game));
            }
            catch (Exception e) {
                return(Problem(detail: e.Message, statusCode: 500));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Create(GameViewModel model, HttpPostedFileBase image)
        {
            // 1) якщо картинка:
            //    2) зберегти картинку на сервер
            // 2.1) конвертувати картинку
            //    3) записати шлях в модель
            if (!ModelState.IsValid)
            {
                return(View());
            }

            if (image != null)
            {
                var fileName = Guid.NewGuid().ToString() + ".jpg";
                Debug.WriteLine(image.ContentType + " " + ImageFormat.Png.ToString());

                if (image.ContentType.Contains("image"))
                {
                    var bitmap = BitmapConvertor.Convert(image.InputStream, 200, 200);

                    if (bitmap != null)
                    {
                        var serverPath = Server.MapPath($"~/Images/{fileName}");

                        bitmap.Save(serverPath);
                        model.Image = $"/Images/{fileName}";
                    }
                }
            }

            await _gameService.AddGameAsync(_mapper.Map <Game>(model));

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <Game> > PostGame(GameModel model)
        {
            try
            {
                var location = _linkGenerator.GetPathByAction("GetGame", "Games", new { id = -1 });
                if (string.IsNullOrWhiteSpace(location))
                {
                    return(BadRequest("Could not use ID"));
                }

                var game = _mapper.Map <Game>(model);

                await _gameService.AddGameAsync(game);

                if (await _sharedRepository.SaveChangesAsync() > 0)
                {
                    return(Created(location, _mapper.Map <GameModel>(game)));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, Settings.DatabaseFailureString));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddGameAsync([SwaggerParameter("game", Required = true)] Game game)
        {
            game.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.Name).Value);

            var gameDto = await _gameService.AddGameAsync(game);

            return(Ok(gameDto));
        }
Ejemplo n.º 5
0
 public async Task <IActionResult> Post([FromBody] GameModel value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     return(Ok(await _service.AddGameAsync(value)));
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> PostGame(GameModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _gameService.AddGameAsync(_mapper.Map <GameBM>(model));

            return(CreatedAtAction(nameof(GetGameById), new { id = model.Id }, model));
        }
        public async Task <IActionResult> Create([Bind("SeasonYear,Week,GuestName,GuestScore,HostName,HostScore,WinnerName,WinnerScore,LoserName,LoserScore,IsPlayoffGame,Notes")] Game game)
        {
            if (ModelState.IsValid)
            {
                await _gameService.AddGameAsync(game);

                await _sharedRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Create)));
            }

            return(View(game));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> CreateGame(GameViewModel model)
        {
            if (ModelState.IsValid)
            {
                GameDto gameDto = new GameDto();
                gameDto.Date   = model.Date;
                gameDto.Id     = model.Id;
                gameDto.Result = model.Result;
                gameDto.Team1  = model.Team1;
                gameDto.Team2  = model.Team2;
                var id = await _gameService.AddGameAsync(gameDto);

                return(RedirectToAction(nameof(Games)));
            }
            else
            {
                return(View(model));
            }
        }
        public async Task <Competition> AddGameAsync(Competition competition)
        {
            // convert to game
            var gameDto = _mapper.Map <Game>(competition);

            var result = await _defaultGameService.AddGameAsync(gameDto);

            // now we add the Chain for a competition as its always the same.
            // submission, moderation, randomdraw

            var submissionEvent = new Event
            {
                Name = "Submission Event",
            };

            var competitionDto = _mapper.Map <Competition>(result);

            return(competitionDto);
        }