Exemplo n.º 1
0
 public IHttpActionResult Update([FromBody] RaceUpdateModel raceToUpdate, [FromUri] int raceId)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _service = new RaceService();
     _service.UpdateRace(raceToUpdate, raceId);
     return(Ok());
 }
Exemplo n.º 2
0
        public void UpdateRace(RaceUpdateModel raceToUpdate, int raceId)
        {
            Race entity = _ctx.Races.Single(e => e.RaceId == raceId);

            if (entity != null)
            {
                if (raceToUpdate.UpdatedRaceName != null)
                {
                    entity.RaceName = raceToUpdate.UpdatedRaceName;
                }
                if (raceToUpdate.UpdatedRaceDescription != null)
                {
                    entity.RaceDescription = raceToUpdate.UpdatedRaceDescription;
                }
                if (raceToUpdate.UpdatedHasSubraces != null)
                {
                    entity.HasSubraces = (bool)raceToUpdate.UpdatedHasSubraces;
                }
                if (raceToUpdate.UpdatedSpeed != null)
                {
                    entity.Speed = raceToUpdate.UpdatedSpeed;
                }
                if (raceToUpdate.UpdatedLanguage != null)
                {
                    entity.Language = raceToUpdate.UpdatedLanguage;
                }
                if (raceToUpdate.UpdatedAbilityScoreIncrease != null)
                {
                    entity.AbilityScoreIncrease = raceToUpdate.UpdatedAbilityScoreIncrease;
                }
                if (raceToUpdate.UpdatedHasDarkvision != null)
                {
                    entity.HasDarkvision = (bool)raceToUpdate.UpdatedHasDarkvision;
                }
                if (raceToUpdate.UpdatedSource != null)
                {
                    entity.Source = raceToUpdate.UpdatedSource;
                }
                if (raceToUpdate.UpdatedOrigin != null)
                {
                    entity.Origin = raceToUpdate.UpdatedOrigin;
                }
                _ctx.SaveChanges();
            }
        }