public IActionResult Put(int id, [FromBody] MakerDTO maker) { var makerDB = this._dbContext.Makers.First(c => c.ID == id); if (!(string.IsNullOrEmpty(maker.Name))) { makerDB.Name = maker.Name; } if (maker.Country != null) { makerDB.CountryID = maker.Country.ID; } this._dbContext.SaveChanges(); return(Ok()); }
public IActionResult Post([FromBody] MakerDTO maker) { if (string.IsNullOrWhiteSpace(maker.Name)) { return(BadRequest()); } Maker newMaker; newMaker = new Maker() { Name = maker.Name, CountryID = maker.Country.ID }; this._dbContext.Makers.Add(newMaker); this._dbContext.SaveChanges(); return(Get(newMaker.ID)); }