Ejemplo n.º 1
0
        public IEnumerable <SubscriptionForSubmitView> CreateSubscriptionsByTextbook(string term, string textbookName, string isbn)
        {
            //删除未征订的订单
            RemoveNotSubscription();
            _subscriptionRepo.Context.Commit();
            //取未征订的申报
            var studentDeclarations = GetNotSubscriptionStudentDeclarationJiaoWu(term);
            var teacherDeclarations = GetNotSubscriptionTeacherDeclarationJiaoWu(term);
            //合并
            var declarations = studentDeclarations.Union <DeclarationJiaoWu>(teacherDeclarations);
            //按教材筛选
            IEnumerable <DeclarationJiaoWu> query;

            //教材名称为空,则按ISBN筛选
            if (string.IsNullOrWhiteSpace(textbookName))
            {
                if (string.IsNullOrWhiteSpace(isbn))
                {
                    query = declarations;
                }
                else
                {
                    query = declarations.Where(t => t.Textbook.Isbn.Contains(isbn));
                }
            }
            else
            {
                query = declarations.Where(t => t.Textbook.Name.Contains(textbookName));
            }
            //生成订单
            var subscriptions = SubscriptionService.CreateSubscriptions(
                query.OfType <StudentDeclarationJiaoWu>(),
                query.OfType <TeacherDeclarationJiaoWu>()
                ).ToList();

            //写入DB
            subscriptions.ForEach(t => _subscriptionRepo.Add(t));
            _subscriptionRepo.Context.Commit();
            //返回
            return(_adapter.Adapt <SubscriptionForSubmitView>(subscriptions.OrderBy(t => t.Textbook.Name)));
        }