public ActionResult Create2(question que) { try { // q = qzs.getbyname(q.quiz_nom); // que.quiz3_quiz_id = q.quiz_id; qss.Add(que); qss.Commit(); // TODO: Add insert logic here return(RedirectToAction("listquiz")); } catch { return(View()); } }
public IActionResult Post([FromBody] QuestionModel questionModel) { bool valid = TryValidateModel(questionModel); if (!valid) { return(BadRequest()); } var description = questionModel._Description.ToUpper(); var hasBeenCreateTheQuestion = _question.Count(a => a.Description.ToUpper().Contains(description)) > 0; if (hasBeenCreateTheQuestion) { return(BadRequest()); } Question question = new Question( questionModel._Description, questionModel._Tips, questionModel._Answer, questionModel._CategoryId, false, // questionModel._Published, //todo make published by role of user! questionModel._Seconds ); if (_category.Count(a => a.Id == questionModel._CategoryId) == 0) { ModelState.AddModelError("CategoryId", "Category not found"); return(BadRequest(ModelState)); } _question.Add(question); _question.Save(); return(Ok(question)); // return CreatedAtRoute("Get", new { id = question.Id }); }