public IActionResult DeleteOEQfromP(int oeQid, int exercisePaperId) { DbSet <ExercisePaper> expp = _dbContext.ExercisePaper; ExercisePaper exppList = expp.Where(c => c.ExercisePaperId == exercisePaperId).FirstOrDefault(); DbSet <OExPaperList> exP = _dbContext.OExPaperList; OExPaperList expItem = exP.Where(c => c.ExercisePaperId == exercisePaperId && c.OEQuestionId == oeQid).FirstOrDefault(); DbSet <OEQuestions> oeQT = _dbContext.OEQuestions; OEQuestions oeQitem = oeQT.Where(c => c.Id == oeQid).FirstOrDefault(); oeQitem.UseCount = oeQitem.UseCount + 1; exppList.TotalQns = exppList.TotalQns - 1; _dbContext.ExercisePaper.Update(exppList); if (expItem != null) { _dbContext.OExPaperList.Remove(expItem); } _dbContext.SaveChanges(); return(Ok()); }
public IActionResult EditOEQP(int oeQid, int exercisePaperId) { DbSet <OEQuestions> oeQ = _dbContext.OEQuestions; OEQuestions oeQItem = oeQ.Where(c => c.Id == oeQid).FirstOrDefault(); DbSet <ExercisePaper> expp = _dbContext.ExercisePaper; ExercisePaper exppList = expp.Where(c => c.ExercisePaperId == exercisePaperId).FirstOrDefault(); DbSet <OExPaperList> exP = _dbContext.OExPaperList; List <OExPaperList> exPList = exP.Where(c => c.OEQuestionId == oeQid).ToList(); DbSet <OEQuestionsPaper> oeqP = _dbContext.OEQuestionsPaper; List <OEQuestionsPaper> oeqPList = oeqP.ToList(); if (oeQItem.UseCount < 1) { if (!(oeqPList.Where(c => c.Id == oeQid).Count() > 0)) { OEQuestionsPaper oeqpS = new OEQuestionsPaper(); oeqpS.Question = oeQItem.Question; oeqpS.Figure = oeQItem.Figure; oeqpS.Answer = oeQItem.Answer; oeqpS.Topic = oeQItem.Topic; if (exPList.Count() == 0) { OExPaperList expItem = new OExPaperList(); expItem.ExercisePaperId = exercisePaperId; expItem.OEQuestionId = oeQid; _dbContext.OExPaperList.Add(expItem); } _dbContext.OEQuestionsPaper.Add(oeqpS); } else { OExPaperList expItem = new OExPaperList(); expItem.ExercisePaperId = exercisePaperId; expItem.OEQuestionId = oeQid; _dbContext.OExPaperList.Add(expItem); } exppList.TotalQns = exppList.TotalQns + 1; _dbContext.ExercisePaper.Update(exppList); _dbContext.SaveChanges(); var figure = oeQItem.Figure.Replace("[nline]", "<br>"); var question = oeQItem.Question.Replace("[nline]", "<br>"); var answer = oeQItem.Answer.Replace("[nline]", "<br>"); OEQuestions oe = new OEQuestions(); oe.Topic = oeQItem.Topic; oe.Figure = figure; oe.Question = question; oe.Answer = answer; oe.Id = oeQItem.Id; oe.UseCount = oeQItem.UseCount; oeQItem.UseCount = oeQItem.UseCount - 1; _dbContext.OEQuestions.Update(oeQItem); _dbContext.SaveChanges(); return(Ok(oe)); } return(Ok()); }