public async Task <ActionResult <Hero> > Post([FromBody] Hero newHero) { try { System.Random random = new System.Random(); int raceNumber = random.Next(1, 5); int careerNumber = random.Next(1, 5); string raceQuery = @" SELECT * FROM race WHERE id = @Id;"; var raceInfo = _db.QueryFirst <Race>(raceQuery, new { Id = raceNumber }); string careerQuery = @" SELECT * FROM career WHERE id = @Id;"; var careerInfo = _db.QueryFirst <Career>(careerQuery, new { Id = careerNumber }); Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newHero.creatorId = userInfo.Id; newHero.Creator = userInfo; newHero.raceId = raceInfo.Id; newHero.careerId = careerInfo.Id; newHero.health = raceInfo.healthMod + careerInfo.healthMod; newHero.rangePower = raceInfo.rangeMod + careerInfo.rangeMod; newHero.magicPower = raceInfo.magicMod + careerInfo.magicMod; newHero.swordPower = raceInfo.swordMod + careerInfo.swordMod; Hero created = _service.Create(newHero); return(Ok(created)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Heroes> Create(Heroes heroes) { _heroesService.Create(heroes); return(CreatedAtRoute("GetBook", new { id = heroes.Id.ToString() }, heroes)); }