public ActionResult <CommandReadDto> CreateCommand(CommandCreateDto commandCreate) { try { //Get platform var platform = _repository.GetPlatformById(commandCreate.PlatformId); if (platform == null) { return(NotFound()); } //Maper var commandModel = _mapper.Map <Command>(commandCreate); commandModel.Platform = platform; //Create _repository.CreateCommand(commandModel); _repository.SaveChanges(); //Read var commandReadDto = _mapper.Map <CommandReadDto>(commandModel); return(CreatedAtRoute(nameof(GetCommandById), new { Id = commandReadDto.Id }, commandReadDto)); // return Created(commandReadDto, ); } catch (Exception) { return(NotFound()); } }
public ActionResult <PlatformReadDto> GetPlatformById(int id) { try { var platform = _repository.GetPlatformById(id); if (platform == null) { return(NotFound()); } return(Ok(_mapper.Map <PlatformReadDto>(platform))); } catch (System.Exception) { return(NotFound()); } }