public void UpdateSubrace(SubraceUpdateModel subraceToUpdate, int subraceId) { Subrace entity = _ctx.Subraces.Single(e => e.SubraceId == subraceId); if (entity != null) { if (subraceToUpdate.UpdatedSubraceName != null) { entity.SubraceName = subraceToUpdate.UpdatedSubraceName; } if (subraceToUpdate.UpdatedSubraceDescription != null) { entity.SubraceDescription = subraceToUpdate.UpdatedSubraceDescription; } if (subraceToUpdate.UpdatedAbilityScoreIncrease != null) { entity.AbilityScoreIncrease = subraceToUpdate.UpdatedAbilityScoreIncrease; } if (subraceToUpdate.UpdatedSource != null) { entity.Source = subraceToUpdate.UpdatedSource; } if (subraceToUpdate.UpdatedOrigin != null) { entity.Origin = subraceToUpdate.UpdatedOrigin; } if (subraceToUpdate.UpdatedRaceId != null) { entity.RaceId = (int)subraceToUpdate.UpdatedRaceId; } _ctx.SaveChanges(); } }
public IHttpActionResult Update([FromBody] SubraceUpdateModel subraceToUpdate, [FromUri] int subraceId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _service = new SubraceService(); _service.UpdateSubrace(subraceToUpdate, subraceId); return(Ok()); }