Ejemplo n.º 1
0
        public CourseViewModel GetDetailCourseById(int id)
        {
            var course              = unitOfWork.Repository <Course>().GetById(id);
            var listTopic           = new List <TopicViewModel>();
            var listLearningOutcome = new List <LearningOutcomeViewModel>();

            foreach (LearningOutcome learningOutcome in course.LearningOutcomes)
            {
                var learningOutcomeVM = new LearningOutcomeViewModel()
                {
                    Id   = learningOutcome.Id,
                    Code = learningOutcome.Code,
                    Name = learningOutcome.Name
                };
                listLearningOutcome.Add(learningOutcomeVM);
            }
            var courseVM = new CourseViewModel()
            {
                CourseId = id,
                Code     = course.Code,
                Name     = course.Name,
                DefaultNumberOfQuestion = course.DefaultNumberOfQuestion.HasValue ? (int)course.DefaultNumberOfQuestion : 0,
                Topic           = listTopic,
                LearningOutcome = listLearningOutcome,
            };

            return(courseVM);
        }
Ejemplo n.º 2
0
        public ActionResult Add(int courseId)
        {
            var learningOutcome = new LearningOutcomeViewModel()
            {
                CourseId = courseId
            };

            return(View(learningOutcome));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(LearningOutcomeViewModel learningoutcome)
        {
            var courseId = learningOutcomeService.UpdateLearningOutcome(learningoutcome);

            //if (courseId == 0)
            //{
            //    return RedirectToAction("Index", "Error");
            //}
            //return RedirectToAction("Detail", "Course", new { itemId = courseId });
            return(RedirectToAction("Category", "Course", new { courseId = learningoutcome.CourseId }));
        }
Ejemplo n.º 4
0
        public LearningOutcomeViewModel GetLearningOutcomeById(int id)
        {
            var learningOutcome = unitOfWork.Repository <LearningOutcome>().GetById(id);
            var result          = new LearningOutcomeViewModel()
            {
                Id       = learningOutcome.Id,
                Code     = learningOutcome.Code,
                Name     = learningOutcome.Name,
                CourseId = (int)learningOutcome.CourseId
            };

            return(result);
        }
Ejemplo n.º 5
0
        public LearningOutcomeViewModel GetLearingOutcomeById(int learningOutcomeId)
        {
            LearningOutcome          learningOutcome          = unitOfWork.Repository <LearningOutcome>().GetById(learningOutcomeId);
            LearningOutcomeViewModel learningOutcomeViewModel = new LearningOutcomeViewModel()
            {
                Id = learningOutcome.Id,
                //Code = learningOutcome.Code != null ? learningOutcome.Code.ToString() : "", //bo field nay dc khong
                CourseId = learningOutcome.CourseId.HasValue ? learningOutcome.CourseId.Value : 0,
                //IsDisable = (bool)learningOutcome.IsDisable != null ? learningOutcome.IsDisable.Value : true, //bo field nay dc khong
                Name = learningOutcome.Name
            };

            return(learningOutcomeViewModel);
        }
Ejemplo n.º 6
0
 public int UpdateLearningOutcome(LearningOutcomeViewModel model)
 {
     try
     {
         var learningOutcome = unitOfWork.Repository <LearningOutcome>().GetById(model.Id);
         learningOutcome.Code = model.Code;
         learningOutcome.Name = model.Name;
         //learningOutcome.CourseId = model.CourseId;
         unitOfWork.Repository <LearningOutcome>().Update(learningOutcome);
         unitOfWork.SaveChanges();
         return(model.CourseId);
     } catch
     {
         return(0);
     }
 }
Ejemplo n.º 7
0
        public List <LearningOutcomeViewModel> GetAllLearningOutcome()
        {
            List <LearningOutcome>          learningOutcomes = unitOfWork.Repository <LearningOutcome>().GetAll().Where(lo => lo.IsDisable == false).ToList();
            List <LearningOutcomeViewModel> result           = new List <LearningOutcomeViewModel>();

            foreach (var learningOutcome in learningOutcomes)
            {
                LearningOutcomeViewModel model = new LearningOutcomeViewModel()
                {
                    Id       = learningOutcome.Id,
                    Code     = learningOutcome.Code,
                    Name     = learningOutcome.Name,
                    CourseId = (int)learningOutcome.CourseId
                };
                result.Add(model);
            }
            return(result);
        }
Ejemplo n.º 8
0
        public int AddLearningOutcome(LearningOutcomeViewModel model)
        {
            try
            {
                var learningOutcome = new LearningOutcome()
                {
                    Code      = model.Code,
                    Name      = model.Name,
                    CourseId  = model.CourseId,
                    IsDisable = false
                };
                var lo = unitOfWork.Repository <LearningOutcome>().InsertAndReturn(learningOutcome);
                unitOfWork.SaveChanges();

                return((int)lo.CourseId);
            }
            catch
            {
                return(0);
            }
        }
Ejemplo n.º 9
0
        public List <LearningOutcomeViewModel> GetLearningOutcomeByCourseId(int CourseId)
        {
            IQueryable <LearningOutcome> LearningOutcomes = unitOfWork.Repository <LearningOutcome>().GetAll();

            List <LearningOutcome> LearningOutcomeByCourse = LearningOutcomes.Where(lo => lo.CourseId == CourseId).ToList();

            List <LearningOutcomeViewModel> learningOutcomeViewModels = new List <LearningOutcomeViewModel>();

            foreach (var learningOutcome in LearningOutcomeByCourse)
            {
                LearningOutcomeViewModel learningOutcomeViewModel = new LearningOutcomeViewModel()
                {
                    Id        = learningOutcome.Id,
                    Code      = learningOutcome.Code != null ? learningOutcome.Code : "",
                    CourseId  = learningOutcome.CourseId.Value,
                    IsDisable = learningOutcome.IsDisable.HasValue && learningOutcome.IsDisable.Value,
                    Name      = learningOutcome.Name
                };
                learningOutcomeViewModel.UpdateIdValue();
                learningOutcomeViewModels.Add(learningOutcomeViewModel);
            }

            return(learningOutcomeViewModels);
        }
Ejemplo n.º 10
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            logService = new LogService();
            bool         isChange = false;
            LogViewModel logModel = new LogViewModel();


            var user   = (UserViewModel)HttpContext.Current.Session["user"];
            int?userId = null;

            if (user != null)
            {
                userId = user.Id;
            }

            ILogService            logger                 = new LogService();
            CourseService          courseService          = new CourseService();
            CategoryService        categoryService        = new CategoryService();
            LearningOutcomeService learningOutcomeService = new LearningOutcomeService();
            LevelService           levelService           = new LevelService();
            int?targetId = null;
            int?importId = null;
            QuestionViewModel oldQuestionModel = new QuestionViewModel();
            QuestionViewModel newQuestionModel = new QuestionViewModel();
            IQuestionService  questionService  = new QuestionService();

            int[] ids;

            if (IdParamName != null && filterContext.ActionParameters.ContainsKey(IdParamName))
            {
                targetId = filterContext.ActionParameters[IdParamName] as Int32?;
            }
            else if (ObjectParamName != null && filterContext.ActionParameters.ContainsKey(ObjectParamName))
            {
                newQuestionModel = filterContext.ActionParameters[ObjectParamName] as QuestionViewModel;
                targetId         = newQuestionModel.GetType().GetProperty(IdParamName).GetValue(newQuestionModel, null) as Int32?;
                if (Action.Equals(Enum.GetName(typeof(LogEnum), LogEnum.Update)) && TargetName.ToLower().Equals("question"))
                {
                    oldQuestionModel = questionService.GetQuestionById(newQuestionModel.Id);
                }
            }
            #region update Log
            if (Action.Equals(Enum.GetName(typeof(LogEnum), LogEnum.Update)) && TargetName.ToLower().Equals("question"))
            {
                QuestionViewModel questionViewModel = new QuestionViewModel();
                oldQuestionModel.QuestionContent = WebUtility.HtmlDecode(oldQuestionModel.QuestionContent);
                if (oldQuestionModel.CategoryId != 0)
                {
                    oldQuestionModel.Category = categoryService.GetCategoryById(oldQuestionModel.CategoryId).Name;
                }

                oldQuestionModel.Category            = oldQuestionModel.CategoryId != 0 ? oldQuestionModel.Category : "[None of Category]";
                oldQuestionModel.LevelName           = oldQuestionModel.LevelId != 0 ? oldQuestionModel.LevelName : "[None of Level]";
                oldQuestionModel.LearningOutcomeName = oldQuestionModel.LearningOutcomeId != 0 ? oldQuestionModel.LearningOutcomeName : "[None of LOC]";
                for (int i = 0; i < oldQuestionModel.Options.Count; i++)
                {
                    oldQuestionModel.Options[i].OptionContent = WebUtility.HtmlDecode(oldQuestionModel.Options[i].OptionContent);
                }
                logModel.OldValue = JsonConvert.SerializeObject(oldQuestionModel);

                if (newQuestionModel.QuestionContent != "")
                {
                    newQuestionModel.QuestionCode = oldQuestionModel.QuestionCode != null?oldQuestionModel.QuestionCode.ToString() : "";

                    newQuestionModel.CourseId = oldQuestionModel.CourseId;
                    //newQuestionModel.CategoryId = oldQuestionModel.CategoryId;
                    if (newQuestionModel.CategoryId != 0)
                    {
                        newQuestionModel.Category = categoryService.GetCategoryById(newQuestionModel.CategoryId).Name;
                    }
                    newQuestionModel.Category = newQuestionModel.CategoryId != 0 ? newQuestionModel.Category : "[None of Category]";
                    if (newQuestionModel.LevelId != 0)
                    {
                        newQuestionModel.LevelName = levelService.GetLevelById(newQuestionModel.LevelId).Name;
                    }
                    newQuestionModel.LevelName = newQuestionModel.LevelId != 0 ? newQuestionModel.LevelName : "[None of Level]";
                    if (newQuestionModel.LearningOutcomeId != 0)
                    {
                        newQuestionModel.LearningOutcomeName = learningOutcomeService.GetLearingOutcomeById(newQuestionModel.LearningOutcomeId).Name;
                    }
                    newQuestionModel.LearningOutcomeName = newQuestionModel.LearningOutcomeId != 0 ? newQuestionModel.LearningOutcomeName : "[None of LOC]";
                    //newQuestionModel.Image = oldQuestionModel.Image;
                    newQuestionModel.CourseName = oldQuestionModel.CourseName;
                    //newQuestionModel.LearningOutcomeName = oldQuestionModel.LearningOutcomeName;
                    //newQuestionModel.LevelName = oldQuestionModel.LevelName;
                    newQuestionModel.QuestionContent = WebUtility.HtmlDecode(newQuestionModel.QuestionContent);
                    for (int i = 0; i < newQuestionModel.Options.Count; i++)
                    {
                        newQuestionModel.Options[i].OptionContent = WebUtility.HtmlDecode(newQuestionModel.Options[i].OptionContent);
                    }
                    logModel.NewValue = JsonConvert.SerializeObject(newQuestionModel);
                }
                logModel.OldValue   = JsonConvert.SerializeObject(oldQuestionModel);
                logModel.NewValue   = JsonConvert.SerializeObject(newQuestionModel);
                logModel.UserId     = userId;
                logModel.TargetId   = targetId;
                logModel.Action     = Action;
                logModel.TargetName = TargetName;
                logModel.LogDate    = DateTime.Now;
                logModel.Message    = Message;
                logModel.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                logModel.Method     = filterContext.ActionDescriptor.ActionName;
                logModel.Fullname   = Fullname;
                logModel.UserCode   = UserCode;
                logger.Log(logModel);
                isChange = true;
            }

            if (Action.Equals(Enum.GetName(typeof(LogEnum), LogEnum.Update)) && TargetName.ToLower().Equals("rule"))
            {
            }
            #endregion

            #region move Question Log
            else if (Action.Equals(Enum.GetName(typeof(LogEnum), LogEnum.Move)) && TargetName.ToLower().Equals("question"))
            {
                int                      categoryId               = 0;
                int                      learningOutComeId        = 0;
                int                      levelId                  = 0;
                CourseViewModel          courseView               = new CourseViewModel();
                LearningOutcomeViewModel learningOutcomeViewModel = new LearningOutcomeViewModel();
                LevelViewModel           levelViewModel           = new LevelViewModel();
                CategoryViewModel        categoryView             = new CategoryViewModel();

                if (filterContext.ActionParameters.ContainsKey(IdParamName))
                {
                    ids               = filterContext.ActionParameters[IdParamName] as int[];
                    categoryId        = filterContext.ActionParameters[CateParamName] != null ? (int)filterContext.ActionParameters[CateParamName] : 0;
                    learningOutComeId = filterContext.ActionParameters[LocParamName] != null ? (int)filterContext.ActionParameters[LocParamName] : 0;
                    levelId           = (int)filterContext.ActionParameters[LevelParamName];
                    if (ids != null)
                    {
                        foreach (var item in ids)
                        {
                            if (item != 0)
                            {
                                targetId         = item;
                                oldQuestionModel = questionService.GetQuestionById((int)targetId);
                                if (oldQuestionModel.CategoryId != 0)
                                {
                                    oldQuestionModel.Category = categoryService.GetCategoryById(oldQuestionModel.CategoryId).Name;
                                }
                                oldQuestionModel.Category = oldQuestionModel.CategoryId != 0 ? oldQuestionModel.Category : "[None of Category]";

                                oldQuestionModel.LevelName           = oldQuestionModel.LevelId != 0 ? oldQuestionModel.LevelName : "[None of Level]";
                                oldQuestionModel.LearningOutcomeName = oldQuestionModel.LearningOutcomeId != 0 ? oldQuestionModel.LearningOutcomeName : "[None of LOC]";
                                newQuestionModel.LearningOutcomeId   = learningOutComeId;
                                newQuestionModel.LevelId             = levelId;
                                if (categoryId != 0)
                                {
                                    newQuestionModel.Category = categoryService.GetCategoryById(categoryId).Name;
                                }
                                newQuestionModel.Category = categoryId != 0 ? newQuestionModel.Category : "[None of Category]";
                                //newQuestionModel.CourseId = oldQuestionModel.CourseId;

                                courseView = courseService.GetCourseById(oldQuestionModel.CourseId);
                                newQuestionModel.CourseName = courseView.Name;
                                if (learningOutComeId != 0)
                                {
                                    learningOutcomeViewModel = learningOutcomeService.GetLearingOutcomeById(learningOutComeId);
                                }
                                newQuestionModel.LearningOutcomeName = learningOutComeId != 0 ? learningOutcomeViewModel.Name : "[None of LOC]";
                                if (levelId != 0)
                                {
                                    levelViewModel = levelService.GetLevelById(levelId);
                                }
                                newQuestionModel.LevelName = levelId != 0 ? levelViewModel.Name : "[None of level]";
                                //newQues.CourseName = oldValue.CourseName;
                                //newQues.LearningOutcomeName = oldValue.LearningOutcomeName;
                                //newQues.LevelName = oldValue.LevelName;
                                newQuestionModel.QuestionContent = oldQuestionModel.QuestionContent;
                                newQuestionModel.Id           = oldQuestionModel.Id;
                                newQuestionModel.QuestionCode = oldQuestionModel.QuestionCode;
                                newQuestionModel.Options      = oldQuestionModel.Options;

                                #region log to db
                                logModel.OldValue   = JsonConvert.SerializeObject(oldQuestionModel);
                                logModel.NewValue   = JsonConvert.SerializeObject(newQuestionModel);
                                logModel.UserId     = userId;
                                logModel.TargetId   = targetId;
                                logModel.Action     = Action;
                                logModel.TargetName = TargetName;
                                logModel.LogDate    = DateTime.Now;
                                logModel.Message    = Message;
                                logModel.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                                logModel.Method     = filterContext.ActionDescriptor.ActionName;
                                logger.Log(logModel);

                                logModel = new LogViewModel();
                                isChange = true;
                                #endregion
                            }
                        }
                    }
                }
            }

            #endregion

            else if (isChange == false)
            {
                logModel.OldValue = OldValue;
                logModel.NewValue = NewValue;
                if (newQuestionModel != null && !String.IsNullOrWhiteSpace(NewValue))
                {
                    for (int i = 0; i < newQuestionModel.Options.Count; i++)
                    {
                        newQuestionModel.Options[i].OptionContent = WebUtility.HtmlDecode(newQuestionModel.Options[i].OptionContent);
                    }
                    logModel.NewValue = JsonConvert.SerializeObject(newQuestionModel);
                }
                if (Action.Equals(Enum.GetName(typeof(LogEnum), LogEnum.Cancel)))
                {
                    logModel.Status = (int)StatusEnum.Canceled;
                }
                if (Action.Equals(Enum.GetName(typeof(LogEnum), LogEnum.Save)))
                {
                    logModel.Status = (int)StatusEnum.Done;
                }
                else
                {
                    logModel.Status = (int)StatusEnum.Checked;
                }
                logModel.OldValue   = JsonConvert.SerializeObject(oldQuestionModel);
                logModel.NewValue   = JsonConvert.SerializeObject(newQuestionModel);
                logModel.UserId     = userId;
                logModel.TargetId   = targetId;
                logModel.Action     = Action;
                logModel.TargetName = TargetName;
                logModel.LogDate    = DateTime.Now;
                logModel.Message    = Message;
                logModel.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                logModel.Method     = filterContext.ActionDescriptor.ActionName;
                logModel.Fullname   = Fullname;
                logModel.UserCode   = UserCode;
                logger.Log(logModel);
            }

            #region comment

            /*if (!Action.ToLower().Equals("move"))
             * {
             *  logModel.UserId = userId;
             *  logModel.TargetId = targetId;
             *  logModel.Action = Action;
             *  logModel.TargetName = TargetName;
             *  logModel.LogDate = DateTime.Now;
             *  logModel.Message = Message;
             *  logModel.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
             *  logModel.Method = filterContext.ActionDescriptor.ActionName;
             *
             * }
             * else
             * {
             *  logModel.UserId = userId;
             *  logModel.TargetId = targetId;
             *  logModel.Action = Action;
             *  logModel.TargetName = TargetName;
             *  logModel.LogDate = DateTime.Now;
             *  logModel.Message = Message;
             *  logModel.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
             *  logModel.Method = filterContext.ActionDescriptor.ActionName;
             *  logModel.Fullname = Fullname;
             *  logModel.UserCode = UserCode;
             * }*/

            //else
            //{
            //    logModel.OldValue = JsonConvert.SerializeObject(oldQuestionModel);
            //    logModel.NewValue = JsonConvert.SerializeObject(newQuestionModel);
            //    logModel.UserId = userId;
            //    logModel.TargetId = targetId;
            //    logModel.Action = Action;
            //    logModel.TargetName = TargetName;
            //    logModel.LogDate = DateTime.Now;
            //    logModel.Message = Message;
            //    logModel.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            //    logModel.Method = filterContext.ActionDescriptor.ActionName;
            //    logModel.Fullname = Fullname;
            //    logModel.UserCode = UserCode;
            //    logger.Log(logModel);
            //}
            #endregion
        }