public ActionResult <MonsterApi.Models.Monster> GetMonster(int id) { MonsterApi.Models.Monster monster = _monsterRepository.GetBy(id); if (monster == null) { return(NotFound()); } return(monster); }
public IActionResult PutMonster(int id, MonsterApi.Models.Monster monster) { if (id != monster.Id) { return(BadRequest()); } _monsterRepository.Update(monster); _monsterRepository.SaveChanges(); return(NoContent()); }
public IActionResult DeleteMonster(int id) { MonsterApi.Models.Monster monster = _monsterRepository.GetBy(id); if (monster == null) { return(NotFound()); } _monsterRepository.Delete(monster); _monsterRepository.SaveChanges(); return(NoContent()); }
public ActionResult <MonsterApi.Models.Monster> PostMonster(MonsterDTO monster) { MonsterApi.Models.Monster monsterToCreate = new MonsterApi.Models.Monster() { Name = monster.Name, Description = monster.Description }; foreach (var m in monster.Moves) { monsterToCreate.AddMove(new Move(m.Name, m.PowerPoints, m.Accuracy, m.Effect, m.BasePower)); } _monsterRepository.Add(monsterToCreate); _monsterRepository.SaveChanges(); return(CreatedAtAction(nameof(GetMonster), new { id = monsterToCreate.Id }, monster)); }
public ActionResult <String> AddImage(int id) { IFormFile files = Request.Form.Files[0]; MonsterApi.Models.Monster monster = _monsterRepository.GetBy(id); if (files != null) { MemoryStream ms = new MemoryStream(); files.CopyTo(ms); Image image = new Image { ImageData = ms.ToArray(), Monster = monster, MonsterId = monster.Id }; _imageRepository.addImage(image); _imageRepository.saveChanges(); return(Ok()); } return(BadRequest()); }