public async Task <IActionResult> PostDNClass([FromBody] DNClass dNClass) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.DNClasses.Add(dNClass); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDNClass", new { id = dNClass.ClassName }, dNClass)); }
public async Task <IActionResult> PutDNClass([FromRoute] string id, [FromBody] DNClass dNClass) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dNClass.ClassName) { return(BadRequest()); } _context.Entry(dNClass).State = EntityState.Modified; try { var dn = _context.DNClasses.Find(id); if (dn == null) { return(NotFound()); } dn.ATKTYPE = dNClass.ATKTYPE; _context.DNClasses.Update(dn); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DNClassExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public DNClassesController(DragonNestContext context) { _context = context; if (!_context.DNClasses.Any()) { var dnClasses = new DNClass[] { new DNClass { ClassName = "Kali", ATKTYPE = MainATK.MAGICAL }, new DNClass { ClassName = "Academic", ATKTYPE = MainATK.MAGICAL } }; foreach (DNClass d in dnClasses) { _context.DNClasses.Add(d); } _context.SaveChanges(); var skills = new Skill[] { new Skill { Name = "Alfredo", DMG = 750, Special = "Summon Alfredo", DNClassID = _context.DNClasses.First(c => c.ClassName == "Academic").ClassName }, new Skill { Name = "Wax", DMG = 0, Special = "Summon the Wax to slow enemy", DNClassID = _context.DNClasses.First(c => c.ClassName == "Academic").ClassName }, new Skill { Name = "Spirit of Genie", DMG = 0, Special = "Increase all the stats of allies for certain period of time by summoning the Spirit of Desert.", DNClassID = _context.DNClasses.First(c => c.ClassName == "Kali").ClassName }, new Skill { Name = "Phantom Guard", DMG = 0, Special = "Summons small spirit to protect oneself.", DNClassID = _context.DNClasses.First(c => c.ClassName == "Kali").ClassName } }; foreach (Skill s in skills) { _context.Skills.Add(s); } _context.SaveChanges(); } }