Ejemplo n.º 1
0
        private void UpdateEntityStudySets(ResponseUpdateView model, Func <string, string> comma)
        {
            var entitySets = EntityStudySetService.GetAll().Select(uw => new {
                courseTCs = "," + uw.CourseTCList.Replace(" ", "") + ",",
                uw
            })
                             .Where(x => x.courseTCs.Contains(comma(model.FromCourseTC))).ToList();

            foreach (var entitySet in entitySets)
            {
                var newCourseTCs = entitySet.courseTCs.Replace(comma(model.FromCourseTC),
                                                               comma(model.ToCourseTC));
                entitySet.uw.CourseTCList = newCourseTCs.Trim(',');
            }
            UserWorkService.SubmitChanges();
        }
Ejemplo n.º 2
0
        public ActionResult Recommendations(RecommendationsVM model)
        {
            var courses          = new List <Course>();
            var completeCourseTC = new List <string>();
            var testCourseTC     = new List <string>();

            foreach (var key in ModelState.Keys)
            {
                ModelState[key].Errors.Clear();
            }
            if (System.Web.HttpContext.Current.Request.IsPost())
            {
                var user = UserService.GetAll(x => x.Email == model.Email).FirstOrDefault();
                if (user == null)
                {
                    var student = StudentService.FirstOrDefault(x =>
                                                                x.StudentEmails.Any(z => z.Email == model.Email));
                    if (student != null)
                    {
                        user = new User {
                            Student = student
                        }
                    }
                    ;
                }
                if (user == null)
                {
                    this.ModelState.AddModelError("", "Слушатель не существует");
                }
                else
                {
                    if ((model.ProductId == 0 && model.ProfessionId == 0) ||
                        (model.ProductId > 0 && model.ProfessionId > 0))
                    {
                        this.ModelState.AddModelError("", "Выберите профессию или продукт");
                    }
                    else
                    {
                        var entityCourseTCList = EntityStudySetService.GetByPK(
                            Math.Max(model.ProductId, model.ProfessionId)).CourseTCList;
                        completeCourseTC = GetCompleteCourses(user);

                        courses = GetCourses(entityCourseTCList, completeCourseTC);
                        if (user.UserID > 0)
                        {
                            var testIds = UserTestService.GetAll(x => x.UserId == user.UserID &&
                                                                 UserTestStatus.PassStatuses.Contains(x.Status))
                                          .Select(x => x.TestId).Distinct().ToList();
                            testCourseTC = SiteObjectRelationService.GetRelation(typeof(Test),
                                                                                 testIds.Cast <object>(), typeof(Course))
                                           .Select(x => x.RelationObject_ID).ToList().Cast <string>()
                                           .ToList();
                        }
                    }
                }
            }
            else
            {
                model = new RecommendationsVM();
            }
            var sets = EntityStudySetService.GetAll().ToList();

            model.Professions       = sets.Where(x => x.Type == 1).OrderBy(x => x.EntityName).ToList();
            model.Products          = sets.Where(x => x.Type == 2).OrderBy(x => x.EntityName).ToList();
            model.Courses           = courses;
            model.TestCourseTCs     = testCourseTC;
            model.CompleteCourseTCs = completeCourseTC;
            return(View(model));
        }