public async Task <ActionResult> SaveScore(int score) { var userId = User.Identity.GetUserId().ToString(); if (score >= 0 && score <= 10) { TodayWord word = TempData["Word"] as TodayWord; IList <TodayWord> todayWords = TempData["ListWords"] as IList <TodayWord>; LectureViewModel model = new LectureViewModel(word, todayWords); // increase exp; await m_expService.AddExpForLearnWordAsync(userId, word.WordId, score, word.WordId); // comple word // save learnword result var result = m_learnWordService.SaveLearnWordResult(model.TodayWord, score); await m_expService.AddExpForContinuousLearningAsync(userId, todayWords); // continues if complete all words TempData["ListWordToDay"] = todayWords; // Update partial view if (result == ServiceResult.Success) { return(PartialView("_ListTodayWordPartial", todayWords)); } } return(Json("error", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Check if user access and get list word or not yet /// </summary> /// <param name="userId">user id</param> /// <param name="classId">class id</param> /// <returns>true or false</returns> private async Task <bool> IsAccessTodayAsync(string userId, string classId) { // Get to day time DateTime today = System.DateTime.Today; // test var www = this.m_classRepository.FindEntity(t => t.Id == classId); // get first word TodayWord word = await this.m_todayWordRepository.FindEntityAsync(t => t.UserId == userId && t.ClassId == classId); // test var words = await this.m_todayWordRepository.FindEntitiesAsync(t => t.ClassId == "tu-vung-co-ban"); int count = words.ToList().Count; // dhkjc if (word == null) { return(false); } // Checking if ((today.Day == word.CreatedDate.Value.Day) && // equal day (today.Month == word.CreatedDate.Value.Month) && // equal month (today.Year == word.CreatedDate.Value.Year)) // equal year { return(true); } else { return(false); } }
public LectureViewModel(TodayWord TodayWord, IList <TodayWord> TodayWords, ViewWordViewModel WordDetails, bool IsAllowView, bool IsAllowLearnAgain, bool IsAllowResume) { this.TodayWord = TodayWord; this.TodayWords = TodayWords; this.WordDetails = WordDetails; // boolean type this.IsAllowView = IsAllowView; this.WordDetails.IsAllowLearnAgain = IsAllowLearnAgain; this.WordDetails.IsAllowResume = IsAllowResume; }
public async Task <ActionResult> Resume(string classId) { DateTime start = DateTime.Now; // begin action // get user id string userId = User.Identity.GetUserId(); // get list word of today IList <TodayWord> todayWords = new List <TodayWord>(); // get lít todaywords todayWords = TempData["ListWordToDay"] as IList <TodayWord>; // ì empty, select new list if (todayWords == null || todayWords.Count == 0) { todayWords = await m_learnWordService.GetListWordsTodayAsync(userId, classId); TempData["ListWordToDay"] = todayWords; } else { // Do nothing } // Get first word to start TodayWord startToDay = await m_learnWordService.GetWordToLearnAsync(todayWords); TempData["FirstWord"] = startToDay; if (startToDay == null) { //return RedirectToAction("Lecture", "LearnWord", //new { area = "galaxygate", classId = classId, wordId = todayWords[0].Word.Id, word = todayWords[0].Word.aWord }); bool isRegistered = await this.m_classService.IsUserRegisteredClassAsync(userId, classId); // if user join class if (isRegistered == true) { // redirect to acction result return(RedirectToAction("ClassInfoAndRegister", "LearnWord", new { area = "galaxygate", classId = classId })); } else { // allow user to register return(RedirectToAction("ClassInfoAndRegister", "LearnWord", new { area = "galaxygate", classId = classId })); } } else { System.Diagnostics.Debug.WriteLine("Resume: {0}", (DateTime.Now - start)); return(RedirectToAction("Lecture", "LearnWord", new { area = "galaxygate", classId = classId, wordId = startToDay.Word.Id, word = startToDay.Word.aWord })); } }
/// <summary> /// Save list today words to database /// </summary> /// <param name="userId">user id</param> /// <param name="words">list of words</param> /// <returns>nothing</returns> private async Task SaveTodayWordsAsync(string userId, IList <Word> words) { DateTime start = System.DateTime.Now; foreach (var word in words) { TodayWord todayword = EntityFactory.CreateTodayWord(userId, word.ClassBelongId, word.Id); // LearnWordHistory history = EntityFactory.CreateLearnWordHistory(userId, word.ClassBelongId, word); await this.m_todayWordRepository.InsertAsync(todayword); // await this.m_learnWordHistoryRepository.InsertAsync(history); } await this.m_todayWordRepository.SaveChangesAsync(); // await this.m_learnWordHistoryRepository.SaveChangesAsync(); System.Diagnostics.Debug.WriteLine("First save data: {0}", (System.DateTime.Now - start)); }
public async Task <ActionResult> Lecture(string classId, string wordId) { DateTime start = DateTime.Now; // begin action // Init values bool isAllowView = true; bool isAllowLearn = true; bool isAllowResume = true; IList <TodayWord> _todayWords = new List <TodayWord>(); TodayWord startToDay = new TodayWord(); // get user id string userId = User.Identity.GetUserId(); //Check user release date before learn (check in LearnWordController action Lecture and in AccountController action GetActiveHistory) // await m_userService.CheckUserReleaseAsync(userId); // get data TodayWord word = TempData["FirstWord"] as TodayWord; IList <TodayWord> todayWords = TempData["ListWordToDay"] as IList <TodayWord>; ViewWordViewModel viewWordVM = new ViewWordViewModel(); // If resume class if (word != null && todayWords != null) { // Loading to view model LectureViewModel model = new LectureViewModel(word, todayWords); // Passing into next request TempData["ListWords"] = todayWords; TempData["Word"] = word; System.Diagnostics.Debug.WriteLine("Lecture {0}", (DateTime.Now - start)); // return view return(View(model)); } // if user calls by url else { // get list word of today _todayWords = await m_learnWordService.GetListWordsTodayAsync(userId, classId); // Check if user has learn this word or not isAllowView = await m_learnWordService.IsAllowToViewAsync(_todayWords, wordId); isAllowLearn = await this.m_learnWordService.IsUserLearnWordBeforeAsync(userId, wordId); isAllowResume = await this.m_classService.IsUserRegisteredClassAsync(userId, classId); // continues // Get word to start startToDay = await m_learnWordService.GetTodayWordAsync(userId, classId, wordId); // if word not found, this is anonymous access if (startToDay == null) { Word w = await m_learnWordService.GetWordByIdAsync(wordId); startToDay = EntityFactory.CreateTodayWord(userId, classId, w, true, false); } else { // Do nothing } } // If anonymous type, load comment only viewWordVM = await this.GetWordDetailsVM(userId, wordId); // Loading to view model LectureViewModel md = new LectureViewModel(startToDay, _todayWords, viewWordVM, isAllowView, isAllowLearn, isAllowResume); // Passing into next request TempData["ListWords"] = _todayWords; TempData["Word"] = startToDay; System.Diagnostics.Debug.WriteLine("Lecture {0}", (DateTime.Now - start)); // return view return(View(md)); }
public LectureViewModel(TodayWord TodayWord, IList <TodayWord> TodayWords) { this.TodayWord = TodayWord; this.TodayWords = TodayWords; }
public async Task <ServiceResult> SaveLearnWordResultAsync(TodayWord todayWord, int archivedScore) { try { DateTime start = DateTime.Now; // Update todayword if (archivedScore > 5) // if result > 5, pass this word { todayWord.IsPassed = true; } else //vice sera { todayWord.IsPassed = false; } //this word was learned todayWord.IsLearned = true; var tmp = this.m_todayWordRepository.FindEntity(x => x.UserId == todayWord.UserId && x.WordId == todayWord.WordId && x.ClassId == todayWord.ClassId); if (tmp != null) { this.m_todayWordRepository.Update(todayWord); } else { this.m_todayWordRepository.Insert(todayWord); } // Save change await this.m_todayWordRepository.SaveChangesAsync(); // Save learn word history LearnWordHistory learnWordHistory = EntityFactory .CreateLearnWordHistory(todayWord.UserId, todayWord.ClassId, todayWord.Word, archivedScore); // Insert history to db await this.m_learnWordHistoryRepository.InsertAsync(learnWordHistory); // Save changes await this.m_learnWordHistoryRepository.SaveChangesAsync(); // Insert new entity // Find Learn word result LearnWordResult learnWordResult = this.m_learnWordResultRepository .FindEntity(t => t.UserId == todayWord.UserId && t.WordId == todayWord.WordId && t.ClassId == todayWord.ClassId); // Check if user has been learn this word or not if (learnWordResult != null) // if user has learn this word { // update result to database if score better if (archivedScore > learnWordResult.AchievedScore) { learnWordResult.AchievedScore = archivedScore; if (archivedScore > 5) { learnWordResult.IsSuccessed = true; } await this.m_learnWordResultRepository.UpdateAsync(learnWordResult); await this.m_learnWordResultRepository.SaveChangesAsync(); } else { // Do nothing } } else // if user has not learn this word { // Create new learn word result for him LearnWordResult newLearnWordResult = EntityFactory .CreateLearnWordResult(todayWord.UserId, todayWord.ClassId, todayWord.WordId, archivedScore); // insert to db await this.m_learnWordResultRepository.InsertAsync(newLearnWordResult); // Save changes await this.m_learnWordResultRepository.SaveChangesAsync(); } System.Diagnostics.Debug.WriteLine("Save learned results async: " + (DateTime.Now - start)); return(ServiceResult.Success); } catch (Exception ex) // exception { return(ServiceResult.AddError(ex.Message)); } }