public ActionResult Post(QuestionNavbar question) { try { if (!ModelState.IsValid) { return(BadRequest()); } _context.Add(question); return(Ok()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public ActionResult <QuestionNavbar> Get(int id) { try { QuestionNavbar question = _context.GetWithId(id); if (question == null) { return(StatusCode(StatusCodes.Status404NotFound)); } return(Ok(question)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public ActionResult Delete(int id) { QuestionNavbar dbQuestion = _context.GetWithId(id); try { foreach (Question item in dbQuestion.Questions) { item.IsDelete = true; } _context.Delete(id); return(Ok()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public ActionResult Update(int id, [FromBody] QuestionNavbar questionNavbar) { try { QuestionNavbar dbQuestion = _context.GetWithId(id); if (dbQuestion == null) { return(BadRequest()); } dbQuestion.Title = questionNavbar.Title; _context.Update(dbQuestion); return(Ok()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public void Update(QuestionNavbar data) { _context.Update(data); }
public void Add(QuestionNavbar data) { _context.Add(data); }