Exemple #1
0
 public ActionResult <MonsterApi.Models.Monster> GetMonster(int id)
 {
     MonsterApi.Models.Monster monster = _monsterRepository.GetBy(id);
     if (monster == null)
     {
         return(NotFound());
     }
     return(monster);
 }
Exemple #2
0
 public IActionResult PutMonster(int id, MonsterApi.Models.Monster monster)
 {
     if (id != monster.Id)
     {
         return(BadRequest());
     }
     _monsterRepository.Update(monster);
     _monsterRepository.SaveChanges();
     return(NoContent());
 }
Exemple #3
0
 public IActionResult DeleteMonster(int id)
 {
     MonsterApi.Models.Monster monster = _monsterRepository.GetBy(id);
     if (monster == null)
     {
         return(NotFound());
     }
     _monsterRepository.Delete(monster);
     _monsterRepository.SaveChanges();
     return(NoContent());
 }
Exemple #4
0
        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));
        }
Exemple #5
0
        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());
        }