コード例 #1
0
        public void Put(int id, [FromBody] Dog dog)
        {
            var thisDog = _db.Dogs.FirstOrDefault(d => d.DogId == id);

            if (dog.Name != null)
            {
                thisDog.Name = dog.Name;
            }
            if (dog.Age != null)
            {
                thisDog.Age = dog.Age;
            }
            if (dog.Breed != null)
            {
                thisDog.Breed = dog.Breed;
            }
            var zeroDate = new DateTime();

            if (dog.Admitted.Equals(zeroDate))
            {
            }
            else
            {
                thisDog.Admitted = dog.Admitted;
            }
            if (dog.Notes != null)
            {
                thisDog.Notes = dog.Notes;
            }
            _db.Entry(thisDog).State = EntityState.Modified;
            _db.SaveChanges();
        }
コード例 #2
0
        public void Put(int id, [FromBody] Cat cat)
        {
            var thisCat = _db.Cats.FirstOrDefault(d => d.CatId == id);

            if (cat.Name != null)
            {
                thisCat.Name = cat.Name;
            }
            if (cat.Age != null)
            {
                thisCat.Age = cat.Age;
            }
            if (cat.Breed != null)
            {
                thisCat.Breed = cat.Breed;
            }
            var zeroDate = new DateTime();

            if (cat.Admitted.Equals(zeroDate))
            {
            }
            else
            {
                thisCat.Admitted = cat.Admitted;
            }
            if (cat.Notes != null)
            {
                thisCat.Notes = cat.Notes;
            }
            _db.Entry(thisCat).State = EntityState.Modified;
            _db.SaveChanges();
        }