//Delete Question with all Options public bool DeleteQuestion(int quesData) { bool result = false; using (myProjectEntities context = new myProjectEntities()) { tblQuizQuestion quesDetail = context.tblQuizQuestions.Where(w => w.PK_Question_id == quesData).FirstOrDefault(); float m1 = (float)quesDetail.marks; tblQuizDetail quizDetail = context.tblQuizDetails.Where(a => a.PK_Quiz_id == quesDetail.FK_Quiz_id).FirstOrDefault(); float m2 = (float)quizDetail.quiz_weightage - m1; quizDetail.quiz_weightage = m2; context.Entry(quizDetail).State = EntityState.Modified; context.SaveChanges(); int q = context.spDeleteQuestionWithOption(quesData); if (q != 0) { result = true; //set return to true } } return(result); }
//Enter Feedback public bool createFeedbackAnswer(FeedbackAnswer feedModel) { bool result = false; float fValue = 0; using (myProjectEntities context = new myProjectEntities()) { Mapper.CreateMap <FeedbackAnswer, tblFeedbackResult>(); tblFeedbackResult newFeed = Mapper.Map <FeedbackAnswer, tblFeedbackResult>(feedModel); context.tblFeedbackResults.Add(newFeed); context.SaveChanges(); var valueFeed = context.tblFeedbackResults.Where(q => q.FK_Feedback_id == feedModel.FK_Feedback_id).Select(q => q.feedback_answer).AsEnumerable(); float d = float.Parse(valueFeed.Aggregate((a, b) => a + b).ToString()); int count = valueFeed.Count(); fValue = d / count; tblFeedback f = context.tblFeedbacks.Where(q => q.PK_Feedback_id == feedModel.FK_Feedback_id).FirstOrDefault(); f.feedback_value = fValue; context.Entry(f).State = EntityState.Modified; context.SaveChanges(); } return(result); }
//Update existing Questions public bool UpdateQuestion(questionModel quesData) { bool result = false; using (myProjectEntities context = new myProjectEntities()) //update weightage { tblQuizQuestion quesDetail = context.tblQuizQuestions.Where(w => w.PK_Question_id == quesData.PK_Question_id).FirstOrDefault(); float m1 = (float)quesDetail.marks; tblQuizDetail quizDetail = context.tblQuizDetails.Where(a => a.PK_Quiz_id == quesData.FK_Quiz_id).FirstOrDefault(); float m2 = (float)quizDetail.quiz_weightage - m1; quizDetail.quiz_weightage = m2 + (float)quesData.marks; context.Entry(quizDetail).State = EntityState.Modified; context.SaveChanges(); } using (myProjectEntities context = new myProjectEntities()) { Mapper.CreateMap <questionModel, tblQuizQuestion>(); tblQuizQuestion newQues = Mapper.Map <questionModel, tblQuizQuestion>(quesData); context.Entry(newQues).State = EntityState.Modified; context.SaveChanges(); } if (quesData.question_type == "Optional" || quesData.question_type == "Multiple Choice") { using (myProjectEntities context = new myProjectEntities()) { List <tblQuizOption> newOpt = context.tblQuizOptions.Where(s => s.FK_Question_id == quesData.PK_Question_id).ToList(); foreach (optionModel item in quesData.optionModel) { foreach (tblQuizOption item1 in newOpt) { if (item.PK_Option_id == item1.PK_Option_id) { item1.isAnswer = item.isAnswer; } } } context.SaveChanges(); } } result = true; return(result); //This is to update just the Question i.e. without option model //Mapper.CreateMap<questionModel, tblQuizQuestion>(); //tblQuizQuestion s = Mapper.Map<questionModel, tblQuizQuestion>(quesData); //context.Entry(s).State = EntityState.Modified; //int q = context.SaveChanges(); //if (q == 1) // result = true; //return result; }
//Update existing Quiz + Change the status to delete the quiz public bool UpdateQuiz(quizModel quizData) { bool result = false; using (myProjectEntities context = new myProjectEntities()) { Mapper.CreateMap <quizModel, tblQuizDetail>(); tblQuizDetail s = Mapper.Map <quizModel, tblQuizDetail>(quizData); context.Entry(s).State = EntityState.Modified; int q = context.SaveChanges(); if (q == 1) { result = true; } return(result); } }
//Update Options public bool UpdateOption(optionModel optionData) { bool result = false; using (myProjectEntities context = new myProjectEntities()) { Mapper.CreateMap <optionModel, tblQuizOption>(); tblQuizOption s = Mapper.Map <optionModel, tblQuizOption>(optionData); context.Entry(s).State = EntityState.Modified; int q = context.SaveChanges(); if (q == 1) { result = true; } return(result); } }
//Update Lecture data public bool updateLecture(lectureModel lectureData) { bool result = false; using (myProjectEntities context = new myProjectEntities()) { Mapper.CreateMap <lectureModel, tblLecture>(); tblLecture s = Mapper.Map <lectureModel, tblLecture>(lectureData); context.Entry(s).State = EntityState.Modified; int q = context.SaveChanges(); if (q == 1) { result = true; } return(result); } }
public bool createFeedAnswer(int studentId, int lectureId, float answer) { bool result = false; float fValue = 0; using (myProjectEntities context = new myProjectEntities()) { int q3 = 0; var feedId = context.tblFeedbacks.Where(q => q.FK_Lecture_id == lectureId).FirstOrDefault(); FeedbackAnswer feedModel = new FeedbackAnswer(); feedModel.feedback_answer = answer; feedModel.feedback_date = System.DateTime.Now; feedModel.FK_Feedback_id = Convert.ToInt32(feedId.PK_Feedback_id); feedModel.FK_Student_id = studentId; Mapper.CreateMap <FeedbackAnswer, tblFeedbackResult>(); tblFeedbackResult newFeed = Mapper.Map <FeedbackAnswer, tblFeedbackResult>(feedModel); context.tblFeedbackResults.Add(newFeed); q3 = context.SaveChanges(); //Now update feedback value in tblFeedback //This is because after every submission there is change in the overall feedback value if (q3 != 0) { var valueFeed = context.tblFeedbackResults.Where(q => q.FK_Feedback_id == feedModel.FK_Feedback_id).Select(q => q.feedback_answer).AsEnumerable(); float d = float.Parse(valueFeed.Aggregate((a, b) => a + b).ToString()); int count = valueFeed.Count(); fValue = d / count; tblFeedback f = context.tblFeedbacks.Where(q => q.PK_Feedback_id == feedModel.FK_Feedback_id).FirstOrDefault(); f.feedback_value = fValue; context.Entry(f).State = EntityState.Modified; q3 = context.SaveChanges(); if (q3 != 0) { result = true; } } } return(result); }
//Updated public int Question_Create(questionModel quesData) { int result = 0; using (myProjectEntities context = new myProjectEntities()) { Mapper.CreateMap <questionModel, tblQuizQuestion>(); tblQuizQuestion newQues = Mapper.Map <questionModel, tblQuizQuestion>(quesData); if (quesData.question_type == "Optional" || quesData.question_type == "Multiple Choice")//Check is not options { List <tblQuizOption> newOpt = new List <tblQuizOption>(); Mapper.CreateMap <optionModel, tblQuizOption>(); foreach (optionModel opt in quesData.optionModel) { tblQuizOption o = Mapper.Map <optionModel, tblQuizOption>(opt); newOpt.Add(o); } newQues.tblQuizOptions = newOpt.ToList(); } context.tblQuizQuestions.Add(newQues); //Execute the add function int q = context.SaveChanges(); if (q > 0) { result = newQues.PK_Question_id; //set return to true } tblQuizDetail quizDetail = context.tblQuizDetails.Where(a => a.PK_Quiz_id == newQues.FK_Quiz_id).FirstOrDefault(); quizDetail.quiz_weightage = quizDetail.quiz_weightage + (float)newQues.marks; context.Entry(quizDetail).State = EntityState.Modified; context.SaveChanges(); } return(result); }