public ActionResult FinishLearning(string IDList) { UserDatasController UDController = new UserDatasController(); Vocabulary_PracticeController VPController = new Vocabulary_PracticeController(); string userName = User.Identity.GetUserName(); var userID = db.UserData.Where(ud => ud.UserName == userName). Select(ud => ud.ID).First(); UserData userData = db.UserData.Find(userID); if (userData.VocabularyList == "" || userData.VocabularyList == "") { userData.VocabularyList += IDList; } else { userData.VocabularyList += "," + IDList; } UDController.Edit(userData); List <string> IDtoList = IDList.Split(',').ToList(); foreach (var vocabID in IDtoList) { Vocabulary_Practice vpData = new Vocabulary_Practice { UserName = userName, VocabularyID = Int32.Parse(vocabID), LastPracticed = DateTime.Now, RepeatInterval = 1 }; VPController.Create(vpData); } return(RedirectToAction("Index")); }
public ActionResult FinishPracticing(string IDString, string goodString, string okayString, string badString) { List <int> IDList = IDString.Split(',').Select(id => Int32.Parse(id)).ToList(); List <int> GoodList = new List <int>(); List <int> OkayList = new List <int>(); List <int> BadList = new List <int>(); if (goodString != "_Good" && goodString.Contains(',')) { GoodList = goodString.Split(',').Select(id => Int32.Parse(id)).ToList(); } else if (goodString != "_Good") { GoodList.Add(Int32.Parse(goodString)); } if (okayString != "_Okay" && okayString.Contains(',')) { OkayList = okayString.Split(',').Select(id => Int32.Parse(id)).ToList(); } else if (okayString != "_Okay") { OkayList.Add(Int32.Parse(okayString)); } if (badString != "_Bad" && badString.Contains(',')) { BadList = badString.Split(',').Select(id => Int32.Parse(id)).ToList(); } else if (badString != "_Bad") { BadList.Add(Int32.Parse(badString)); } Vocabulary_PracticeController VPController = new Vocabulary_PracticeController(); List <Vocabulary_Practice> vocabulary_PracticeList = db.Vocabulary_Practice.Where(vp => IDList.Contains(vp.ID)).ToList(); foreach (var vocabularyPractice in vocabulary_PracticeList) { if (vocabularyPractice.RepeatInterval <= db.RepeatInterval.Count() + 1) { if (GoodList.Contains(vocabularyPractice.VocabularyID)) { vocabularyPractice.RepeatInterval += 1; double interval = db.RepeatInterval.Where(ri => ri.ID == vocabularyPractice.RepeatInterval).Select(ri => ri.Interval).First(); vocabularyPractice.LastPracticed = DateTime.Now.AddDays(interval); //TODO fix multiple instances of EntityChanger db.SaveChanges(); //VPController.Edit(vocabularyPractice); } if (OkayList.Contains(vocabularyPractice.VocabularyID)) { double interval = db.RepeatInterval.Where(ri => ri.ID == vocabularyPractice.RepeatInterval).Select(ri => ri.Interval).First(); vocabularyPractice.LastPracticed = DateTime.Now.AddDays(interval); //TODO fix multiple instances of EntityChanger db.SaveChanges(); //VPController.Edit(vocabularyPractice); } if (BadList.Contains(vocabularyPractice.VocabularyID)) { if (vocabularyPractice.RepeatInterval > 1) { vocabularyPractice.RepeatInterval -= 1; } double interval = db.RepeatInterval.Where(ri => ri.ID == vocabularyPractice.RepeatInterval).Select(ri => ri.Interval).First(); vocabularyPractice.LastPracticed = DateTime.Now.AddDays(interval); //TODO fix multiple instances of EntityChanger db.SaveChanges(); //VPController.Edit(vocabularyPractice); } } } return(RedirectToAction("Index")); }