Ejemplo n.º 1
0
        public async Task <ActionResult <Pet> > Update([FromBody] PetPost model, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }

            Pet pet = await db.Pet
                      .Where(k => k.id_pet == id)
                      .FirstOrDefaultAsync();

            if (pet == null)
            {
                return(NotFound(new {
                    ok = false,
                    err = "The id " + id + " does not exist in the records"
                }));
            }

            AssignsControllers.AssingPet(model, pet);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (System.Exception err)
            {
                return(BadRequest(new {
                    ok = false,
                    err = new {
                        message = err.InnerException.Message
                    }
                }));
            }
            return(Ok(new {
                ok = true,
                pet
            }));
        }
        public async Task <ActionResult <FoundationPost> > Update([FromBody] FoundationPost model, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }

            Foundation foundation = await db.Foundation
                                    .Where(k => k.id_foundation == id)
                                    .FirstOrDefaultAsync();

            if (foundation == null)
            {
                return(NotFound(new {
                    ok = false,
                    err = "The id " + id + " does not exist in the records"
                }));
            }

            AssignsControllers.AssingFoundation(model, foundation);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (System.Exception err)
            {
                return(BadRequest(new {
                    ok = false,
                    err = err.InnerException.Message
                }));
            }

            return(Ok(new {
                ok = true,
                foundation
            }));
        }