public async Task <IHttpActionResult> PutCharacterType(int id, CharacterType characterType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != characterType.Id) { return(BadRequest()); } _db.Entry(characterType).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharacterTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <UpdateCharacterResponse> Update(UpdateCharacterRequest request) { var character = await _db.Characters.FindAsync(request.Id); var characterType = await _db.CharacterTypes.FindAsync(request.CharacterTypeId); character.Name = request.Name; character.NumberOfComics = request.NumberOfComics; character.NumberOfSeries = request.NumberOfSeries; character.ProfilePage = request.ProfilePage; character.CharacterType = characterType; _db.Entry(character).State = EntityState.Modified; await _db.SaveChangesAsync(); return(new UpdateCharacterResponse { Success = true }); }