public async Task <IActionResult> PutDepartments(int id, Departments departments) { if (id != departments.Id) { return(BadRequest()); } _context.Entry(departments).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Answers> > PostAnswers([FromBody] AnswerDTO answers) { var question = await _context.Questions.SingleOrDefaultAsync(q => q.Label == answers.Question); var department = await _context.Departments.SingleOrDefaultAsync(d => d.DepartmentName == answers.Department); if (question == null || department == null) { return(BadRequest("Either the question or the department does not exist.")); } if (answers.Answer > question.MaxPossible) { return(BadRequest("Answer not in range.")); } var answer = new Answers { DepartmentId = department.Id, QuestionId = question.Id, Answer = answers.Answer / question.MaxPossible * 100, Datetime = DateTime.Now, Question = question, Department = department }; _context.Answers.Add(answer); await _context.SaveChangesAsync(); return(Ok(answers)); }