Ejemplo n.º 1
0
        public string Buy([FromBody] int courseId)
        {
            //var bought = DB.MyOrder.Any(x => x.CUSTOMER_ID == AuthCustomer.CustomerId && x.OnLineCourseId == courseId && x.PAYMWNT_STATUS == ConstValue.OrderStatus.Paid);
            //if (bought)
            //    throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, MakeMessage("请勿重复购买")));

            var course = DB.OnlineCourse.AsNoTracking().Where(x => x.id == courseId).FirstOrDefault();

            if (course == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }


            string orderNumber = "O" + courseId + DateTime.Now.ToString("yyyyMMddHHmmss") + WebFunctions.GetRandomWords(3);

            MyOrder newOrder = new MyOrder()
            {
                ORDER_NUMBER   = orderNumber,
                OnLineCourseId = courseId,
                CUSTOMER_ID    = AuthCustomer.CustomerId,
                DATE           = DateTime.Now,
                NAME           = course.name,
                PRICE_PRODUCT  = (double)course.price,
                PRICE_PAY      = (double)course.price,
                TOTAL          = (double)course.price,
                PAYMWNT_STATUS = ConstValue.OrderStatus.Unpaid,
            };

            DB.MyOrder.Add(newOrder);
            DB.SaveChanges();

            return(orderNumber);
        }