예제 #1
0
        public List <DinoModel> Put(int id, [FromBody] string name, string imageurl, string length, string weight, string habitat)
        {
            var dino = new DinoModel();
            List <DinoModel> dinosaurs = dino.GetDinosaurs();

            if (dinosaurs.Any(i => i.ID == id))
            {
                dino          = dinosaurs.SingleOrDefault(w => w.ID == id);
                dino.Name     = name;
                dino.ImageURL = imageurl;
                dino.Length   = length;
                dino.Weight   = weight;
                dino.Habitat  = habitat;
            }
            else
            {
                var newDino = new DinoModel
                {
                    ID       = id,
                    Name     = name,
                    ImageURL = imageurl,
                    Length   = length,
                    Weight   = weight,
                    Habitat  = habitat
                };
                dinosaurs.Add(newDino);
            }
            return(dinosaurs);
        }
예제 #2
0
        public DinoModel Get(int id)
        {
            var dino = new DinoModel();
            List <DinoModel> dinosaurs = dino.GetDinosaurs();

            return(dinosaurs[id - 1]);
        }
예제 #3
0
        public List <DinoModel> Get()
        {
            var dino = new DinoModel();
            List <DinoModel> dinosaurs = dino.GetDinosaurs();

            return(dinosaurs);
        }
예제 #4
0
        public List <DinoModel> Delete(int id)
        {
            var dino = new DinoModel();
            List <DinoModel> dinosaurs = dino.GetDinosaurs();

            dino = dinosaurs.SingleOrDefault(i => i.ID == id);
            dinosaurs.Remove(dino);
            return(dinosaurs);
        }
예제 #5
0
        public List <DinoModel> Post([FromBody] int id, string name, string imageurl, string length, string weight, string habitat)
        {
            var dino = new DinoModel();
            List <DinoModel> dinosaurs = dino.GetDinosaurs();
            var newDino = new DinoModel
            {
                ID       = id,
                Name     = name,
                ImageURL = imageurl,
                Length   = length,
                Weight   = weight,
                Habitat  = habitat
            };

            dinosaurs.Add(newDino);
            return(dinosaurs);
        }