Esempio n. 1
0
 public ActionResult Save(Dog dog)
 {
     if (ModelState.IsValid)
     {
         if (string.IsNullOrEmpty(dog.Owner))
             dog.Owner = CustomerIdentityField;
         var addedDog = DogDB.AddOrUpdateDog(dog);
         return new JsonResult2
         {
             Data = addedDog,
             ContentEncoding = Encoding.UTF8,
             ContentType = HttpContext.Request.ContentType
         };
     }
     return new HttpStatusCodeResult(400, "Invalid Dog");
 }
Esempio n. 2
0
        public static Dog AddOrUpdateDog(Dog dog)
        {
            if(dog.ID == 0)
            {
                dog.ID = IDCount++;
                Dogs.Add(dog);
            } else
            {
                var toUpdate = Dogs.SingleOrDefault(x => x.ID == dog.ID);
                toUpdate.Age = dog.Age;
                toUpdate.Breed = dog.Breed;
                toUpdate.Name = dog.Name;
                toUpdate.Owner = dog.Owner;
            }

            return dog;
        }