Пример #1
0
 public void Given_Different_Repo_Use_Partial_Function_to_apply_different_repo_finally_return_BusObj1()
 {
     BusinessRepo <ClassEnrolled, int> classesEnrolled            = ClassesEnrolled.Select(x => (val: x, key: x.id)).ToList();
     BusinessRepo <Code_Value, int>    ClassificationRepo         = codevalues.Where(y => y.CodeSetId == 3).Select(x => (val: x, key: x.Id)).ToList();
     BusinessRepo <Code_Value, int>    SubjectRepo                = codevalues.Where(x => x.CodeSetId == 4).Select(x => (val: x, key: x.Id)).ToList();
     BusinessRepo <Person, int>        peopleRepo                 = lst.Select(x => (val: x, key: x.Id)).ToList();
     Func <Person, Code_Value, Option <StudentBL> > CreateStudent =
         (p, Classification_cv)
         => p.ClassificationId == Classification_cv.Id?Some(new StudentBL
     {
         StudentID      = $"{p.Id}-{p.Name}",
         Name           = p.Name,
         classification = Classification_cv.Name
     }):None;
     Func <int, int, string> createkeyy =
         (pid, cv)
         => $"{pid}={cv}";
     BusinessRepo <Func <Person, Code_Value, Option <StudentBL> >, Func <int, int, string> > CreateStudentRepo1 =
         (val : CreateStudent, key : createkeyy);
     var a1 = CreateStudentRepo1
              .Apply(peopleRepo)
              .Apply(ClassificationRepo)
              .Data
              .Values
              .SelectMany(x => x.AsEnumberable());
 }
Пример #2
0
        public void Given_Different_Repo_Use_Partial_Function_to_apply_different_repo_finally_return_BusObj()
        {
            BusinessRepo <ClassEnrolled, int> classesEnrolled    = ClassesEnrolled.Select(x => (val: x, key: x.id)).ToList();
            BusinessRepo <Code_Value, int>    ClassificationRepo = codevalues.Where(y => y.CodeSetId == 3).Select(x => (val: x, key: x.Id)).ToList();
            BusinessRepo <Code_Value, int>    SubjectRepo        = codevalues.Where(x => x.CodeSetId == 4).Select(x => (val: x, key: x.Id)).ToList();
            BusinessRepo <Person, int>        peopleRepo         = lst.Select(x => (val: x, key: x.Id)).ToList();
            Func <List <Code_Value>, List <Person>, List <StudentBL> > CreateStudent =
                (lstClassifications, people)
                => people.Select(x => new StudentBL
            {
                StudentID      = $"{x.Id}-{x.Name}",
                Name           = x.Name,
                classification = lstClassifications.SingleOrDefault(y => y.Id == x.ClassificationId).Name
            }).ToList();

            Func <Person, Student> createStd = (p) => new Student {
                StudentID = $"{p.Id}-{p.Name}", Name = p.Name
            };
            Func <int, string> createID = i => i.ToString();
            BusinessRepo <Func <Person, Student>, Func <int, string> > CreateStudentRepo = (val : createStd, key : createID);
            var res = CreateStudentRepo.Apply(peopleRepo);

            Assert.Equal(lst.Where(x => x.CategoryType == 1).Count(), res.Data.Count());
            Assert.Contains(new[] { "Tom", "Bob", "Bill" }, t => res.Data.Values.Select(x => x.Name).Contains(t));
        }
Пример #3
0
        public void Given_Different_Repo_Use_Partial_Function_to_apply_different_repo_finally_return_BusObj2()
        {
            var aaa = ClassesEnrolled.Select(x => x.id).Distinct();
            BusinessRepo <ClassEnrolled, int> classesEnrolledRepo = ClassesEnrolled.Select(x => (val: x, key: x.id)).ToBusinessRepo();
            BusinessRepo <Code_Value, int>    ClassificationRepo  = codevalues.Where(y => y.CodeSetId == 3).Select(x => (val: x, key: x.Id)).ToBusinessRepo();
            BusinessRepo <Code_Value, int>    SubjectRepo         = codevalues.Where(x => x.CodeSetId == 4).Select(x => (val: x, key: x.Id)).ToBusinessRepo();
            BusinessRepo <Person, int>        peopleRepo          = lst.Select(x => (val: x, key: x.Id)).ToBusinessRepo();
            Func <Person, Code_Value, ClassEnrolled, Option <StudentSchedule> > CreateStudent =
                (p, Classification_cv, classEnroll)
                => p.ClassificationId == Classification_cv.Id && p.Id == classEnroll.studentId ? Some(new StudentSchedule
            {
                Id             = $"{p.Id}-{p.Name}",
                studentName    = p.Name,
                classification = Classification_cv.Name,
                studentId      = p.Id,
                ClassesIn      = new List <Option <ClassEnrolledIn> >(new[] { classEnroll.studentId == p.Id ? Some(new ClassEnrolledIn {
                        Subject = classEnroll.ClassEnroll_cv.ToString(), room = classEnroll.room
                    }) : None })
            }) : None;
            Func <int, int, int, string> createkeyy =
                (pid, cv, cls)
                => $"{pid}-{cv}-{cls}";
            BusinessRepo <Func <Person, Code_Value, ClassEnrolled, Option <StudentSchedule> >, Func <int, int, int, string> > CreateStudentRepo1 =
                (val : CreateStudent, key : createkeyy);
            var a1 = CreateStudentRepo1
                     .Apply(peopleRepo)
                     .Apply(ClassificationRepo)
                     .Apply(classesEnrolledRepo)
                     .Data
                     .Values
                     .SelectMany(x => x.AsEnumberable())
                     .GroupBy(y => y.Id);
            var test = CreateStudentRepo1
                       .Apply(peopleRepo)
                       .Apply(ClassificationRepo)
                       .Apply(classesEnrolledRepo);
            //.Data;
            // .Values;

            //var b1 = a1.Select(b => b.SelectMany(y => y.ClassesIn));
            //group by id then sum up by adding all classes enrolled per student
            var c1 = a1.Select(y => new StudentSchedule
            {
                Id             = y.First().Id,
                classification = y.First().classification,
                studentId      = y.First().studentId,
                studentName    = y.First().studentName,
                ClassesIn      = y.SelectMany(z => z.ClassesIn).ToList()
            });

            Assert.True(true);
        }
Пример #4
0
 public BusinessController()
 {
     _bRepo = new BusinessRepo();
 }