public void Delete(TEntity entityToDelete) { if (_dbContext.Entry(entityToDelete).State == EntityState.Detached) { _dbSet.Attach(entityToDelete); } _dbSet.Remove(entityToDelete); _dbContext.SaveChanges(); }
public IHttpActionResult PutVotingSession(VotingSession votingSession) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Entry(votingSession).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VotingSessionExists(votingSession.Id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutVoter(Voter voter) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Entry(voter).State = EntityState.Modified; foreach (var question in voter.SecretQuestions) { if (question.Id == 0) { db.Entry(question).State = EntityState.Added; } else { db.Entry(question).State = EntityState.Modified; } } try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VoterExists(voter.Id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }