public async Task <IActionResult> PostEvaluationQuestions([FromBody] EvaluationQuestions evaluation) { if (!ModelState.IsValid) { return(Ok(new Response { IsError = true, Status = 400, Message = "Sai dữ liệu đầu vào" })); } evaluation.Date = DateTime.Now; _context.EvaluationQuestions.Add(evaluation); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(Ok(new Response { IsError = true, Status = 409, Message = "Không thể lưu" })); } return(Ok(new Response { Status = 204 })); }
public async Task <IActionResult> PutEvaluationQuestions([FromRoute] int id, [FromBody] EvaluationQuestions evaluationQuestions) { if (!ModelState.IsValid) { return(Ok(new Response { IsError = true, Status = 400, Message = "Sai dữ liệu đầu vào" })); } if (id != evaluationQuestions.EvaluationId) { return(Ok(new Response { IsError = true, Status = 400, Message = "Sai dữ liệu đầu vào" })); } _context.Entry(evaluationQuestions).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EvaluationQuestionsExists(id)) { return(Ok(new Response { IsError = true, Status = 404, Message = "Không tìm thấy dữ liệu" })); } else { throw; } } return(Ok(new Response { Status = 204 })); }