Ejemplo n.º 1
0
        public ActionResult FinishLearning(string IDList)
        {
            UserDatasController      UDController = new UserDatasController();
            Kanas_PracticeController KPController = new Kanas_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.KanaList == "")
            {
                userData.KanaList += IDList;
            }
            else
            {
                userData.KanaList += "," + IDList;
            }
            UDController.Edit(userData);

            List <string> IDtoList = IDList.Split(',').ToList();

            foreach (var kanaId in IDtoList)
            {
                Kana_Practice kpData = new Kana_Practice
                {
                    UserName       = userName,
                    KanaID         = Int32.Parse(kanaId),
                    LastPracticed  = DateTime.Now.AddDays(1),
                    RepeatInterval = 1
                };

                KPController.Create(kpData);
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        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));
            }
            Kanas_PracticeController KPController = new Kanas_PracticeController();

            List <Kana_Practice> kana_PracticeList = db.Kana_Practice.Where(kp => IDList.Contains(kp.ID)).ToList();

            foreach (var kanaPractice in kana_PracticeList)
            {
                if (kanaPractice.RepeatInterval <= db.RepeatInterval.Count() + 1)
                {
                    if (GoodList.Contains(kanaPractice.KanaID))
                    {
                        kanaPractice.RepeatInterval += 1;
                        double interval = db.RepeatInterval.Where(ri => ri.ID == kanaPractice.RepeatInterval).Select(ri => ri.Interval).First();
                        kanaPractice.LastPracticed = DateTime.Now.AddDays(interval);
                        //TODO fix multiple instances of EntityChanger
                        db.SaveChanges();
                        //VPController.Edit(vocabularyPractice);
                    }
                    if (OkayList.Contains(kanaPractice.KanaID))
                    {
                        double interval = db.RepeatInterval.Where(ri => ri.ID == kanaPractice.RepeatInterval).Select(ri => ri.Interval).First();
                        kanaPractice.LastPracticed = DateTime.Now.AddDays(interval);
                        //TODO fix multiple instances of EntityChanger
                        db.SaveChanges();
                        //VPController.Edit(vocabularyPractice);
                    }
                    if (BadList.Contains(kanaPractice.KanaID))
                    {
                        if (kanaPractice.RepeatInterval > 1)
                        {
                            kanaPractice.RepeatInterval -= 1;
                        }
                        double interval = db.RepeatInterval.Where(ri => ri.ID == kanaPractice.RepeatInterval).Select(ri => ri.Interval).First();
                        kanaPractice.LastPracticed = DateTime.Now.AddDays(interval);
                        //TODO fix multiple instances of EntityChanger
                        db.SaveChanges();
                        //VPController.Edit(vocabularyPractice);
                    }
                }
            }
            return(RedirectToAction("Index"));
        }