Beispiel #1
0
        public ActionResult CheckOrder(long?OrderId, string cartItemStr = "", string totalAmount = "")
        {
            Order order = new Order();
            OrderConfirmViewModel orderConfirmViewModel = new OrderConfirmViewModel();
            long    customerId = (Session[Constants.SESSION_USER] as Customer).Id;
            Address address    = _readFromDb.Address.Where(x => x.CustomerId == customerId && x.IsDefault).FirstOrDefault();

            if (address == null)
            {
                return(Content("<script>alert('请添加收货地址。');location.href='/Address/GetAddress'</script>"));
            }
            else
            {
                if (OrderId == null)
                {
                    string[]         cartItemsIdList = cartItemStr.Split(';');
                    List <OrderItem> orderItems      = new List <OrderItem>();
                    for (int i = 0; i < cartItemsIdList.Length - 1; i++)
                    {
                        if (!string.IsNullOrEmpty(cartItemsIdList[i]))
                        {
                            long      cartItemsId = Convert.ToInt64(cartItemsIdList[i]);
                            CartItem  cartItem    = _readFromDb.CartItems.Where(x => x.Id == cartItemsId).FirstOrDefault();
                            OrderItem orderItem   = new OrderItem();
                            orderItem.ProductId     = cartItem.ProductId;
                            orderItem.Quantity      = cartItem.Quantity;
                            orderItem.UnitPrice     = cartItem.PricePerProduct;
                            orderItem.DiscountPrice = cartItem.PricePerProduct;
                            orderItems.Add(orderItem);

                            _cartItemRepository.UpdateCartItem(cartItem.Id);
                        }
                    }

                    order.CustomerId     = customerId;
                    order.TotalAmount    = Convert.ToDecimal(totalAmount);
                    order.OrderStatus    = Constants.OBLIGATION;
                    order.OrderDate      = DateTime.Now;
                    order.DeliveryDate   = Convert.ToDateTime("1970-01-01 00:00:00.000");
                    order.OrderItems     = orderItems;
                    order.AddressId      = address.Id;
                    order.IsSpecialOrder = false;
                    order.SpecialType    = string.Empty;
                    try
                    {
                        order = _orderService.AddOrder(order);
                        order = _readFromDb.Orders.Where(x => x.Id == order.Id).FirstOrDefault();
                    }
                    catch (System.Exception) { }
                }
                else
                {
                    order           = _orderRepository.GetOrderByOrderId((long)OrderId);
                    order.AddressId = _readFromDb.Address.Where(x => x.CustomerId == customerId && x.IsDefault).FirstOrDefault().Id;
                    _orderRepository.UpdateOrder(order);
                    order = _readFromDb.Orders.Where(x => x.Id == OrderId).FirstOrDefault();
                }

                try
                {
                    decimal actuallyAmount = 0;
                    foreach (OrderItem orderItem in order.OrderItems)
                    {
                        actuallyAmount += orderItem.Product.Price * orderItem.Quantity;
                    }
                    orderConfirmViewModel.ActuallyAmount = actuallyAmount;
                    orderConfirmViewModel.DisCountAmount = actuallyAmount - order.TotalAmount;
                    orderConfirmViewModel.order          = order;
                    orderConfirmViewModel.OrderId        = order.Id;
                    orderConfirmViewModel.ProvinceList   = _provinceRepository.GetProvince();
                    orderConfirmViewModel.CityList       = _cityRepository.GetCity();
                    orderConfirmViewModel.AreaList       = _areaRepository.GetArea();
                }
                catch (Exception ex) { }
                return(View(orderConfirmViewModel));
            }
        }
Beispiel #2
0
        public IActionResult BuyCourse(int id)
        {
            int orderid = _orderservice.AddOrder(User.Identity.Name, id);

            return(Redirect("/UserPanel/MyOrders/ShowOrder/" + orderid));
        }