コード例 #1
0
        public IActionResult PartiallyUpdate(int id, [FromBody] JsonPatchDocument <Thing> patchDoc)
        {
            if (patchDoc == null)
            {
                return(BadRequest());
            }

            Thing existingEntity = _thingsRepository.GetSingle(id);

            if (existingEntity == null)
            {
                return(NotFound());
            }

            Thing thing = existingEntity;

            patchDoc.ApplyTo(thing, ModelState);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Thing updatedThing = _thingsRepository.Update(id, thing);

            return(Ok(updatedThing));
        }
コード例 #2
0
        public IActionResult Update(UpdateThingModel thing)
        {
            if (thing == null)
            {
                return(BadRequest("Thing is null"));
            }

            if (!_thingsRepository.ThingExists(thing.Id))
            {
                return(NotFound($"{thing.Id} not found"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            _thingsRepository.Update(thing);

            return(NoContent());
        }
コード例 #3
0
 public IActionResult OnPost()
 {
     Types = htmlHelper.GetEnumSelectList <ThingType>();
     if (ModelState.IsValid)
     {
         if (Thing.Id == 0)
         {
             thingsRepo.Add(Thing);
             TempData["Message"] = "Thing added";
         }
         else
         {
             thingsRepo.Update(Thing);
             TempData["Message"] = "Thing updated";
         }
         thingsRepo.SaveChanges();
         return(RedirectToPage("./Detail", new { thingId = Thing.Id }));
     }
     else
     {
         return(Page());
     }
 }