public CategoryController(ICategoryServices categoryServices) { this._categoryServices = categoryServices; if (_categoryServices.Count() == 0) { List <Category> items = new List <Category>(); items.Add(new Category("Regular Question")); items.Add(new Category("C#")); items.Add(new Category("PHP")); items.Add(new Category("Ruby and Rails")); items.Add(new Category("Javascript")); items.Add(new Category("Java")); items.Add(new Category("Data Analysis - BI")); items.Add(new Category("SQL Server")); items.Add(new Category("General")); foreach (var categorias in items) { _categoryServices.Add(categorias); } _categoryServices.Save(); } }
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 }); }