public async Task <IActionResult> Post([FromBody] FaqQuestion question) { question.CreatedAt = DateTime.Now; await _context.FaqQuestions.AddAsync(question); await _context.SaveChangesAsync(); return(Json(question)); }
public async Task <IActionResult> Delete(long id) { var question = new FaqQuestion { Id = id }; _context.FaqQuestions.Attach(question); _context.Entry(question).State = EntityState.Deleted; await _context.SaveChangesAsync(); return(Ok()); }
public IActionResult Post(long id, [FromBody] FaqQuestion faqQuestion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } faqManager.SaveQuestion(faqQuestion); return(CreatedAtAction(nameof(Get), new { categoryId = faqQuestion.Category.Id, questionId = faqQuestion.Id }, new HALResponse(faqQuestion).AddLinks(new Link[] { new Link(Link.RelForSelf, $"api/v1/faq/categories/{faqQuestion.Category.Id}/questions/{faqQuestion.Id}") }))); }
public async Task <IActionResult> Answer(long id, [FromBody] FaqQuestion answeredQuestion) { if (answeredQuestion == null) { return(BadRequest()); } var question = await _context.FaqQuestions.SingleOrDefaultAsync(q => q.Id == id); question.Answer = answeredQuestion.Answer; question.AnswererName = answeredQuestion.AnswererName; question.AnswerDate = DateTime.Now; await _context.SaveChangesAsync(); return(Json(question)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { var fg1 = new FaqGroup { FaqGroupId = 1, Title = "Introduction" }; var fg2 = new FaqGroup { FaqGroupId = 2, Title = "Who is this for?" }; var fq1 = new FaqQuestion { Id = 1, Question = "Why is Red Hat making .NET Core 2.0 available?", Answer = ".NET Core on Red Hat platforms complements Java EE in the enterprise.", FaqGroupId = 1 }; var fq2 = new FaqQuestion { Id = 2, Question = "How does .NET Core 2.0 fit into Red Hat plans/portfolio?", Answer = ".NET Core is an important addition to the massive and growing list of " + "open source development tools and platforms.", FaqGroupId = 1 }; var fq3 = new FaqQuestion { Id = 3, Question = "Why would I want to run my .NET apps on Red Hat platforms?", Answer = "Containers and microservices are the main reasons. Red Hat will be able " + "to differentiate .NET Core to run natively on containers that support an open " + "hybrid cloud strategy.", FaqGroupId = 2 }; modelBuilder.Entity <FaqGroup>().HasData(fg1, fg2); modelBuilder.Entity <FaqQuestion>(entity => { entity.HasOne(d => d.FaqGroup) .WithMany(p => p.Questions) .HasForeignKey("FaqGroupId"); }); modelBuilder.Entity <FaqQuestion>().HasData(fq1, fq2, fq3); base.OnModelCreating(modelBuilder); }
public FaqQuestion GetQuestion(long id) { if (id <= 0) { throw new ArgumentOutOfRangeException(nameof(id)); } FaqQuestion question = _context.FaqQuestions .FirstOrDefault(a => a.Id == id); if (question == null) { throw new KeyNotFoundException($"Question with ID: {id} is not found"); } return(question); }
public async Task DeleteQuestion(long id) { if (id <= 0) { throw new ArgumentOutOfRangeException(nameof(id)); } FaqQuestion question = _context.FaqQuestions.SingleOrDefault(a => a.Id == id); if (question == null) { throw new ArgumentNullException(nameof(id), $"Question with ID: {id} not found!"); } _context.FaqQuestions.Remove(question); await _context.SaveChangesAsync(); }
public IActionResult Put(long categoryId, long questionId, [FromBody] FaqQuestion faqQuestion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (faqQuestion.Category.Id != categoryId && faqQuestion.Id != questionId) { return(BadRequest()); } faqManager.SaveQuestion(faqQuestion); return(Ok(new HALResponse(faqQuestion).AddLinks(new Link[] { new Link(Link.RelForSelf, $"api/v1/faq/categories/{faqQuestion.Category.Id}/questions/{faqQuestion.Id}") }))); }
public ActionResult CreateQuestion([FromBody] FaqQuestionCreateUpdateVM question) { if (question == null || db.FaqGroups.FirstOrDefault(g => g.FaqGroupId == question.FaqGroupId) == null) { return(BadRequest()); } var questionEntity = new FaqQuestion { Question = question.Question, Answer = question.Answer, FaqGroupId = question.FaqGroupId }; db.FaqQuestions.Add(questionEntity); db.SaveChanges(); return(Ok()); }
public async Task SaveQuestion(FaqQuestion faqQuestion) { if (faqQuestion == null) { throw new ArgumentNullException(nameof(faqQuestion)); } if (faqQuestion.Id <= 0) { // We are creating a new one // Only need to adjust the id to be 0 and save it in the db. _context.FaqQuestions.Add(faqQuestion); } else { // Get the tracked faqQuestion using the ID EntityEntry <FaqQuestion> entityEntry = _context.Entry(faqQuestion); entityEntry.State = EntityState.Modified; } await _context.SaveChangesAsync(); }
public Task SaveQuestion(FaqQuestion question) { return(_faqRepository.SaveQuestion(question)); }
/// <summary> /// There are no comments for FaqQuestion in the schema. /// </summary> public void AddToFaqQuestion(FaqQuestion faqQuestion) { base.AddObject("FaqQuestion", faqQuestion); }
/// <summary> /// Create a new FaqQuestion object. /// </summary> /// <param name="question_ID">Initial value of Question_ID.</param> public static FaqQuestion CreateFaqQuestion(int question_ID) { FaqQuestion faqQuestion = new FaqQuestion(); faqQuestion.Question_ID = question_ID; return faqQuestion; }