public ActionResult Edit([Bind(Include = "Vid,Date,VBitcoin,VEthereum,VBitcoinCash,VLitecoin,VRipple")] VoteFinal voteFinal) { if (ModelState.IsValid) { db.Entry(voteFinal).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(voteFinal)); }
public ActionResult Edit([Bind(Include = "ID,name")] chart chart) { if (ModelState.IsValid) { db.Entry(chart).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(chart)); }
public ActionResult Edit(TopicViewModel topicVM) { Topic topic = db.Topics.Find(topicVM.Topic.Id); topic.Name = topicVM.Topic.Name; if (ModelState.IsValid) { db.Entry(topic).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index", "Home", new { area = "" })); }
public ActionResult Edit(ExerciseViewModel exerciseVM) { Exercis exercise = new Exercis(); exercise = db.Exercises.SingleOrDefault(x => x.Id == exerciseVM.Exercise.Id); exercise.Question = exerciseVM.Exercise.Question; exercise.Hint = exerciseVM.Exercise.Hint; exercise.CorrectAnswer = exerciseVM.Exercise.CorrectAnswer; exercise.Answer1 = exerciseVM.Exercise.Answer1; exercise.Answer2 = exerciseVM.Exercise.Answer2; exercise.Answer3 = exerciseVM.Exercise.Answer3; exercise.Answer4 = exerciseVM.Exercise.Answer4; if (ModelState.IsValid) { db.Entry(exercise).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Show", "Example", new { exampleID = exerciseVM.Exercise.ExampleID })); }
public ActionResult StoreStudentRecord(ExampleViewModel exampleVM) { bool checkExist = false; int userID = (int)Session["userID"]; int exerciseID = exampleVM.StudentRecord.ExerciseID; Exercis currentExercise = db.Exercises.SingleOrDefault(x => x.Id == exerciseID); string submittedAnswer = exampleVM.StudentRecord.TempAnswer; string correctAnswer = ""; if (currentExercise.CorrectAnswer == "Answer1") { correctAnswer = currentExercise.Answer1; } else if (currentExercise.CorrectAnswer == "Answer2") { correctAnswer = currentExercise.Answer2; } else if (currentExercise.CorrectAnswer == "Answer3") { correctAnswer = currentExercise.Answer3; } else if (currentExercise.CorrectAnswer == "Answer4") { correctAnswer = currentExercise.Answer4; } checkExist = db.StudentRecords.Any(x => x.UserID == userID && x.ExerciseID == exerciseID); StudentRecord existingStudentRecord = db.StudentRecords.SingleOrDefault(x => x.UserID == userID && x.ExerciseID == exerciseID); if (checkExist && existingStudentRecord.CorrectAttempt == null) { //if student record exist update the record. if (existingStudentRecord.Attempt2 == null) { existingStudentRecord.Attempt2 = submittedAnswer; if (submittedAnswer == correctAnswer) { existingStudentRecord.CorrectAttempt = "Attempt2"; } } else if (existingStudentRecord.Attempt3 == null) { existingStudentRecord.Attempt3 = submittedAnswer; if (submittedAnswer == correctAnswer) { existingStudentRecord.CorrectAttempt = "Attempt3"; } } else { existingStudentRecord.Attempt4 = submittedAnswer; if (submittedAnswer == correctAnswer) { existingStudentRecord.CorrectAttempt = "Attempt4"; } } existingStudentRecord.Date = DateTime.Now; if (ModelState.IsValid) { db.Entry(existingStudentRecord).State = EntityState.Modified; db.SaveChanges(); } } else if (!checkExist) { //if student record not exist then create a new student record StudentRecord newStudentRecord = new StudentRecord(); newStudentRecord.UserID = userID; newStudentRecord.ExerciseID = exerciseID; newStudentRecord.Attempt1 = submittedAnswer; if (submittedAnswer == correctAnswer) { newStudentRecord.CorrectAttempt = "Attempt1"; } newStudentRecord.Date = DateTime.Now; db.StudentRecords.Add(newStudentRecord); db.SaveChanges(); } //send feedback string feedbackMessage; if (submittedAnswer == correctAnswer) { feedbackMessage = "Well done! Correct Answer."; } else { feedbackMessage = "Wrong Answer!"; } return(RedirectToAction("Show", "Example", new { exampleID = currentExercise.ExampleID, feedback = feedbackMessage })); }
public ActionResult EditChartVal(ChartTemplate chartTemplate) { chart resultChart = db.charts.Where(s => s.ID == chartTemplate.id).FirstOrDefault <chart>(); resultChart.name = chartTemplate.name; db.Entry(resultChart).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); var intentionVal = db.intentions.Where(p => p.chartID == chartTemplate.id); foreach (var intenDim in intentionVal) // update intention table { db.intentions.Remove(intenDim); } db.Entry(resultChart).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); if (chartTemplate.comparison) { intention tableIntention = new intention(); tableIntention.chartID = chartTemplate.id; tableIntention.intention1 = "Comparison"; db.intentions.Add(tableIntention); db.SaveChanges(); } if (chartTemplate.composition) { intention tableIntention = new intention(); tableIntention.chartID = chartTemplate.id; tableIntention.intention1 = "Composition"; db.intentions.Add(tableIntention); db.SaveChanges(); } if (chartTemplate.distribution) { intention tableIntention = new intention(); tableIntention.chartID = chartTemplate.id; tableIntention.intention1 = "Distribution"; db.intentions.Add(tableIntention); db.SaveChanges(); } if (chartTemplate.relationship) { intention tableIntention = new intention(); tableIntention.chartID = chartTemplate.id; tableIntention.intention1 = "Relationship"; db.intentions.Add(tableIntention); db.SaveChanges(); } foreach (var dimList in chartTemplate.dimentionList) { chartDimension chartDim = db.chartDimensions.Where(s => s.chartID == chartTemplate.id).Where(p => p.dimensionIndex == dimList.dimensionIndex).FirstOrDefault <chartDimension>(); chartDim.isContinuous = Convert.ToInt32(dimList.dimensionIndex); db.Entry(chartDim).State = System.Data.Entity.EntityState.Modified; try { db.SaveChanges(); } catch (Exception e) { } var dimContext = db.dimensionContexts.Where(s => s.dimensionID == dimList.dimensionIndex); foreach (var listDimContext in dimContext) { db.dimensionContexts.Remove(listDimContext); } try { db.SaveChanges(); }catch (Exception e) { } if (dimList.cardinalityAny) { dimensionContext dimCon = new dimensionContext(); dimCon.dimensionID = dimList.dimensionIndex; dimCon.context = "Any"; db.dimensionContexts.Add(dimCon); } if (dimList.contextTimeseries) { dimensionContext dimCon = new dimensionContext(); dimCon.dimensionID = dimList.dimensionIndex; dimCon.context = "Time series"; db.dimensionContexts.Add(dimCon); } if (dimList.contextNumeric) { dimensionContext dimCon = new dimensionContext(); dimCon.dimensionID = dimList.dimensionIndex; dimCon.context = "Numeric"; db.dimensionContexts.Add(dimCon); } if (dimList.contextNominal) { dimensionContext dimCon = new dimensionContext(); dimCon.dimensionID = dimList.dimensionIndex; dimCon.context = "Nominal"; db.dimensionContexts.Add(dimCon); } if (dimList.contextLocation) { dimensionContext dimCon = new dimensionContext(); dimCon.dimensionID = dimList.dimensionIndex; dimCon.context = "Location"; db.dimensionContexts.Add(dimCon); } } try { db.SaveChanges(); } catch (Exception e) { } return(RedirectToAction("ChartList", "Admin")); }