public void DeleteQuestion(int questionId) { var userId = _authManager.GetLoggedUser().UserId; var question = _db.Questions.FirstOrDefault(e => e.QuestionId == questionId && e.User.UserId == userId); if (question != null) { _db.Entry <Question>(question).State = System.Data.Entity.EntityState.Deleted; _db.SaveChanges(); } else { throw new QuizException("Question not found"); } }
public void Empty <T>() where T : class { foreach (var entity in _context.Set <T>()) { _context.Entry(entity).State = EntityState.Deleted; } }
public async Task <IActionResult> PutQuiz(int id, Quiz quiz) { if (id != quiz.ID) { return(BadRequest()); } _context.Entry(quiz).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuizExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutQuestion([FromRoute] int id, [FromBody] Question question) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != question.QuestionId) { return(BadRequest()); } _context.Entry(question).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QuestionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCategory(int id, Category category) { if (id != category.CategoryId) { return(BadRequest()); } _context.Entry(category).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Put(int id, [FromBody] Question question) { if (id != question.Id) { return(BadRequest()); } _context.Entry(question).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(question)); }
public async Task <IActionResult> Put(int id, [FromBody] Models.Question question) //id passed to explicity modify and check { if (id != question.QuestId) { return(BadRequest()); } context.Entry(question).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok(question)); }
public async Task <IActionResult> Put(int id, [FromBody] Question question) { if (id != question.Id) { return(BadRequest()); } //var result = await context.QuestionSet.SingleOrDefaultAsync(q=>q.Id==id); context.Entry(question).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok(question)); // console.log(question); }
public async Task <IActionResult> Put(int id, [FromBody] Question EditedQuestion) { if (id != EditedQuestion.Id) { return(BadRequest()); } //var oldQuestion =await context.Questions.FirstOrDefaultAsync(Question => Question.Id == id); //if (oldQuestion == null) // return NotFound(); //oldQuestion.Text = EditedQuestion.Text; //oldQuestion.CorrectAnswer = EditedQuestion.CorrectAnswer; //oldQuestion.WrongAnswer1 = EditedQuestion.WrongAnswer1; //oldQuestion.WrongAnswer2 = EditedQuestion.WrongAnswer2; //oldQuestion.WrongAnswer3 = EditedQuestion.WrongAnswer3; //context.SaveChanges(); context.Entry(EditedQuestion).State = EntityState.Modified; await context.SaveChangesAsync().ConfigureAwait(false); return(Ok(EditedQuestion)); }
public async Task <IHttpActionResult> PutUsers(User uses) { // Workaround when database is not avaliable if (ConfigurationManager.AppSettings["UseEnvironmentDatabase"].Equals("true")) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Entry(uses).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(T o) { _ctx.Entry(o).State = EntityState.Modified; new Logger().Info("Updating entity of type " + typeof(T).Name + " with id " + o.Id); }
public void Update(T entity) { _context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified; Save(); }