コード例 #1
0
ファイル: LearnWordController.cs プロジェクト: userkimcs/ef
        private async Task <ViewWordViewModel> GetWordDetailsVM(string currentUserId, string wordId)
        {
            // get current word info
            Word currentWord = await this.m_learnWordService.GetWordByIdAsync(wordId);

            // Current page index, default by 1
            // Get comments
            IList <WordComment> wordComments = await this.m_commentService
                                               .GetWordCommentsAsync(wordId, currentUserId, 1, NUMBER_OF_COMMENTS_PER_PAGE);

            // Convert to comment view model
            IList <WordCommentViewModel> comments = new List <WordCommentViewModel>();

            // Mapping
            foreach (WordComment wordComment in wordComments)
            {
                WordCommentViewModel comment = new WordCommentViewModel
                {
                    Comment       = wordComment,
                    IsLiked       = await this.m_commentService.IsLikedCommentAsync(currentUserId, wordComment.Id),
                    IsAllowDelete = currentUserId == wordComment.UserId ? true : false,
                };
                comments.Add(comment);
            }
            // Create view model
            ViewWordViewModel model = new ViewWordViewModel(comments, currentWord);

            return(model);
        }
コード例 #2
0
ファイル: LearnWordController.cs プロジェクト: userkimcs/ef
        public async Task <ActionResult> PostComment(ViewWordViewModel model, string wordId)
        {
            if (!String.IsNullOrWhiteSpace(model.Comment))
            {
                // get account id
                string userId = await Task.Run(() => User.Identity.GetUserId());

                // add comment
                WordComment comment = await this.m_commentService.PostWordCommentAsync(userId, wordId, model.Comment);

                // Check result
                if (comment != null)
                {
                    // Update target
                    return(PartialView("_WordCommentPartial", comment));
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
コード例 #3
0
ファイル: LearnWordController.cs プロジェクト: userkimcs/ef
        public async Task <ActionResult> WordDetails(string wordId)
        {
            // get current user Id
            string userId = User.Identity.GetUserId();
            // Create view model
            ViewWordViewModel model = await GetWordDetailsVM(userId, wordId);

            // Add session
            Session["FilterType"] = "Date";
            // return model
            return(PartialView("_WordDetailsPartial", model));
        }
コード例 #4
0
ファイル: LearnWordController.cs プロジェクト: userkimcs/ef
        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));
        }