public async Task <ActionResult <FoundationPost> > Create([FromBody] FoundationPost model) { if (!ModelState.IsValid) { return(BadRequest(model)); } Foundation foundation = new Foundation(); await db.AddAsync(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 })); }
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 })); }