コード例 #1
0
        public List <DinosaurModel> Put(int id, [FromBody] string name, string size, string weight, string period, string habitats)
        {
            var dino        = new DinosaurModel();
            var listofDinos = dino.GetDinosaurs();

            if (listofDinos.Any(i => i.ID == id))
            {
                dino          = listofDinos.SingleOrDefault(x => x.ID == id);
                dino.Name     = name;
                dino.Size     = size;
                dino.Weight   = weight;
                dino.Period   = period;
                dino.Habitats = habitats;
            }
            else
            {
                var newDino = new DinosaurModel
                {
                    ID       = listofDinos.Count + 1,
                    Name     = name,
                    Size     = size,
                    Weight   = weight,
                    Period   = period,
                    Habitats = habitats
                };
                listofDinos.Add(newDino);
            }

            return(listofDinos);
        }
コード例 #2
0
        public DinosaurModel Get(int id)
        {
            var dino = new DinosaurModel();
            List <DinosaurModel> dinos = dino.GetDinosaurs();

            return(dinos[id - 1]);
        }
コード例 #3
0
        public List <DinosaurModel> Get()
        {
            var dino = new DinosaurModel();
            List <DinosaurModel> dinos = dino.GetDinosaurs();

            return(dinos);
        }
コード例 #4
0
        public List <DinosaurModel> Delete(int id)
        {
            var dino        = new DinosaurModel();
            var listofDinos = dino.GetDinosaurs();

            dino = listofDinos.SingleOrDefault(i => i.ID == id);
            listofDinos.Remove(dino);
            return(listofDinos);
        }
コード例 #5
0
        public List <DinosaurModel> Post([FromBody] string name, string size, string weight, string period, string habitats)
        {
            var dino        = new DinosaurModel();
            var listofDinos = dino.GetDinosaurs();
            var newDino     = new DinosaurModel
            {
                ID       = listofDinos.Count + 1,
                Name     = name,
                Size     = size,
                Weight   = weight,
                Period   = period,
                Habitats = habitats
            };

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