Exemplo n.º 1
0
        /// <summary>
        /// 【1】基于装饰器设计模式为核心业务切入方法
        /// 这个缺点很明显 每个方法都要实现特定的一个装饰器,重复很多的工作
        /// </summary>
        static void Method1(CourseOrder order)
        {
            Console.WriteLine("\r\n\r\n---------【1】基于装饰器设计模式为核心业务切入方法");
            var method = new AOPBasedDecorator(new OrderService());

            method.SubmitOrder(order);
        }
Exemplo n.º 2
0
        public JsonResult SubmitOrder(CourseOrder model)
        {
            if (model == null)
            {
                return(Error("参数错误"));
            }
            if (model.MajorId == 0)
            {
                return(Error("请选择您计划学的专业"));
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                return(Error("请输入您的姓名"));
            }
            if (string.IsNullOrEmpty(model.Phone))
            {
                return(Error("请输入您的微信号"));
            }
            var result = new ResultBase();

            result.success = _courseOrderService.InsertAsync(model);
            if (result.success)
            {
                result.success = _mailInfoService.SendMail("课程预约", model.Country.GetDescription(), model.MajorId, model.Name, model.Phone, model.Email, "",
                                                           new List <string>(), System.Web.HttpContext.Current.Server.MapPath("/"));
            }
            return(Json(result));
        }
Exemplo n.º 3
0
        public JsonResult SubmitOrder(CourseOrder model)
        {
            if (model == null)
            {
                return(Error("参数错误"));
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                return(Error("请选择您计划去的国家"));
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                return(Error("请选择您计划学的专业"));
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                return(Error("请输入您的姓名"));
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                return(Error("请输入您的手机号"));
            }
            var result = new ResultBase();

            result.success = _courseOrderService.InsertAsync(model);
            return(Json(result));
        }
Exemplo n.º 4
0
        public int SubmitOrder(CourseOrder order)
        {
            //在这里编写具体的查询业务...

            Console.WriteLine("--------------------------------《核心业务》课程订单被正确提交...");

            return(1000);
        }
Exemplo n.º 5
0
        public int SubmitOrder(CourseOrder order)
        {
            //其他的业务逻辑
            Console.WriteLine("执行核心业务逻辑之前执行的方法");

            //这个是核心业务
            orderService.SubmitOrder(order);
            return(1);
        }
Exemplo n.º 6
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            //input就是传入的参数
            CourseOrder order = input.Inputs[0] as CourseOrder;

            //在这里编写缓存写入的具体过程....

            Console.WriteLine("缓存写入成功!");

            return(getNext()(input, getNext)); //前进到下一个注入的行为,并返回结果
        }
Exemplo n.º 7
0
        /// <summary>
        /// 传统的方法
        /// 【0】基于普通的接口编程
        /// </summary>
        static void Method0(CourseOrder order)
        {
            //创建订单信息对象

            //【1】基于普通的接口编程
            Console.WriteLine("\r\n\r\n---------【0】基于普通接口编程\r\n");
            IOrderService orderService = new OrderService();
            int           result       = orderService.SubmitOrder(order);

            Console.WriteLine("订单提交返回结果:" + result);
        }
Exemplo n.º 8
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            //input就是传入的参数
            CourseOrder order = input.Inputs[0] as CourseOrder;

            //在这里编写日志的具体实现过程....


            Console.WriteLine("日志写入成功!");

            return(getNext()(input, getNext));
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            CourseOrder order = new CourseOrder
            {
                CourseId    = 1001,
                CourseName  = ".NET高级VIP课程",
                CoursePrice = 3500,
                SchoolId    = 502102,
                StudentId   = 293400
            };

            Method0(order);
            Method1(order);
            Method2(order);

            Console.WriteLine("Hello World!");
        }
Exemplo n.º 10
0
        public bool InsertAsync(CourseOrder model)
        {
            using (var conn = DapperFactory.GetConnection())
            {
                var fields = model.ToFields(removeFields: new List <string> {
                    "Id", "MajorName", "MajorNameEn", "CourseName", "CourseNameEn"
                });
                if (fields == null || fields.Count == 0)
                {
                    return(false);
                }

                model.CreateTime = DateTime.Now;

                string sql = string.Format("insert into [CourseOrder] ({0}) values ({1});", string.Join(",", fields), string.Join(",", fields.Select(n => "@" + n)));
                return(conn.Execute(sql, model) > 0);
            }
        }
Exemplo n.º 11
0
        public bool InsertAsync(CourseOrder model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model不能为null");
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                throw new ArgumentNullException("姓名不能为空");
            }

            if (string.IsNullOrEmpty(model.Phone))
            {
                throw new ArgumentNullException("手机不能为空");
            }

            return(_courseOrderRepository.InsertAsync(model));
        }
Exemplo n.º 12
0
        public async Task <ActionResult> OnGet(Guid id)
        {
            string userId = string.Empty;

            if (User.Identity.IsAuthenticated)
            {
                userId = User.Claims.FirstOrDefault(x => x.Type == "sub").Value;
            }
            CourseOrder = await couseOrderService.GetMyOrder(id, userId);

            if (CourseOrder == null || CourseOrder.Status != OrderStatus.Payed)
            {
                return(Redirect("/Courses/TrailerCourse?id=" + id.ToString()));
            }

            CourseData = await courseExploreService.GetCourseAsync(id);

            return(Page());
        }
Exemplo n.º 13
0
        }                             //决定方法的执行顺序

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            //input是传入的参数
            CourseOrder order = input.Inputs[0] as CourseOrder;

            //校验过程
            if (order.StudentId.ToString().Length < 5)
            {
                return(input.CreateExceptionMethodReturn(new Exception("学员学号不能小于5位!")));
            }
            if (order.CoursePrice < 0)
            {
                return(input.CreateExceptionMethodReturn(new Exception("课程价格不能小于0!")));
            }
            Console.WriteLine("实体数据校验成功!");

            //前进到下一个注入的行为并返回结果
            return(getNext.Invoke().Invoke(input, getNext)); //简化写法:getNext()(input, getNext)
        }
Exemplo n.º 14
0
        private void OnSubmitOrder(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var queue = new MessageQueue(CourseOrder.CourseOrderQueueName))
                {
                    string cource  = (CourcesComboBox.SelectedItem as string) ?? string.Empty;
                    string company = CompanyTextBox.Text;
                    string contact = ContactTextBox.Text;

                    var currentCourseOrder = new CourseOrder
                    {
                        Course = new Course {
                            Title = cource
                        },
                        Customer = new Customer {
                            Company = company, Contact = contact
                        }
                    };

                    using (var message
                               = new Message(currentCourseOrder)
                    {
                        Recoverable = true,
                        Priority =
                            MessageConfiguration.HighPriority == true ? MessagePriority.High : MessagePriority.Normal
                    })
                    {
                        queue.Send(message, string.Format("Course order {{{0}}}", currentCourseOrder.Customer.Company));
                    }
                }

                MessageBox.Show(this, "Course order submitted", "Course order", MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            catch (MessageQueueException messageQueueException)
            {
                MessageBox.Show(this, messageQueueException.Message, "Course Order Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 【2】基于动态代理方式为核心业务切入方法
        /// 1.先实现一个拦截器
        /// 2.实现接口的方法 如果要时间拦截器 需要用virtual 方法
        /// </summary>
        static void Method2(CourseOrder order)
        {
            Console.WriteLine("\r\n\r\n---------【2】基于动态代理方式为核心业务切入方法");

            ProxyGenerator generator   = new ProxyGenerator();//为类或接口提供代理对象
            AOPBasedCastle interceptor = new AOPBasedCastle();

            //建议Castle动态完成对象创建
            IOrderService orderService4 = generator.CreateClassProxy <OrderServiceCastle>(interceptor);
            var           result        = orderService4.SubmitOrder(order);

            #region 其他
            //orderService4.GetAllOrders();
            //Console.WriteLine("订单提交返回结果:" + result);

            // Console.WriteLine("结束了------------------------------");
            //var list= orderService4.GetAllOrders();
            #endregion


            Console.ReadLine();
        }
Exemplo n.º 16
0
        public async Task <CourseOrder> CreateOrder(Guid courseId)
        {
            var memberId = User.Claims.First(x => x.Type == "sub").Value;
            var course   = await exploreService.GetCourseAsync(courseId);

            var orderId    = Guid.NewGuid();
            var orderModel = new CourseOrder
            {
                Id         = orderId,
                CourseId   = courseId,
                CreateTime = DateTime.Now,
                MemberId   = memberId,
                Fee        = (course.Price * 100).ToString(),
                Name       = "Order - " + course.Name,
                Status     = OrderStatus.Create,
                Price      = course.Price,
                Desc       = course.Description,
                OrderType  = OrderType.Course,
                PayChannel = PayChannel.WeChatNative
            };
            await courseOrderService.CreateOrder(orderModel);

            return(orderModel);
        }
Exemplo n.º 17
0
 public async Task CreateOrder(CourseOrder courseOrder)
 {
     dbContext.CourseOrder.Add(courseOrder);
     await dbContext.SaveChangesAsync();
 }
Exemplo n.º 18
0
 public CourseOrderEventArgs(CourseOrder courseOrder)
 {
     this.CourseOrder = courseOrder;
 }
Exemplo n.º 19
0
 public void AddCourseOrder(CourseOrder courseOrder)
 {
     CourseOrderAdd?.Invoke(this, new CourseOrderEventArgs(courseOrder));
 }
Exemplo n.º 20
0
 public async Task UpdateOrder(CourseOrder order)
 {
     dbContext.CourseOrder.Update(order);
     await dbContext.SaveChangesAsync();
 }