public async Task <IActionResult> AddGame([FromForm] GameCreationDto game) { try { game.ImageName = await SaveImage(game.ImageFile); Game g = _mapper.Map <Game>(game); g = _gamesServices.AddGame(g); return(CreatedAtRoute("GetGame", new { id = g.Id }, g)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <IActionResult> Create(CreateGameModel game) { var genres = await _commonService.GetAllGenres(); List <SelectListItem> listItems = _mapper.Map <IEnumerable <Genre>, List <SelectListItem> >(genres); game.Genres = listItems; if (ModelState.IsValid) { await _gamesService.AddGame(game); return(RedirectToAction(nameof(GamesController.Index), new { pageNumber = 1 })); } return(View(game)); }
public ActionResult Post([FromBody] Game value, string source = "API") { var result = _service.AddGame(value); if (result.Status == eOperationStatus.Success) { _service.AddEvent(new Event { GameId = result.Data, EventTypeId = (int)eEventType.Edit, TimeStamp = DateTime.Now, Source = source }); return(Ok(new { Success = result.Data })); } return(BadRequest(new { Message = result.ExceptionMessage })); }