Esempio n. 1
0
        public async Task<IHttpActionResult> PutRace(int id, UpdateRaceBindingModel updateRaceModel)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            var race = await TheRaceStore.FindByIdAsync(id);

            if (race == null)
                return NotFound();

            UpdateEntity(ref race, updateRaceModel);

            var result = await TheRaceStore.UpdateAsync(race);

            return !result.Succeeded
                ? GetErrorResult(result)
                : Ok();
        }
Esempio n. 2
0
 protected void UpdateEntity(ref Race race, UpdateRaceBindingModel updateRaceModel)
 {
     if (updateRaceModel.Name != null)
         race.Name = updateRaceModel.Name;
     if (updateRaceModel.Description != null)
         race.Description = updateRaceModel.Description;
     if (updateRaceModel.Experience.HasValue)
         race.Experience = updateRaceModel.Experience.Value;
 }