Пример #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));
            }
        }
Пример #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"));
        }
Пример #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));
            }
        }
Пример #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));
        }
Пример #5
0
 public async Task <IActionResult> Post([FromBody] GameModel value)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     return(Ok(await _service.AddGameAsync(value)));
 }
Пример #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));
        }
Пример #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);
        }