示例#1
0
        public virtual Result <SubmitOrderModel> SubmitOrder()
        {
            var result = new Result <SubmitOrderModel>();
            var model  = new SubmitOrderModel();

            try
            {
                ManagerResponse <CartResult, Sitecore.Commerce.Entities.Carts.Cart> currentCart = this.CartManager.GetCurrentCart(this.StorefrontContext.ShopName, this.VisitorContext.ContactId);
                if (!currentCart.ServiceProviderResult.Success)
                {
                    result.SetErrors(currentCart.ServiceProviderResult);
                    return(result);
                }

                ManagerResponse <SubmitVisitorOrderResult, Order> managerResponse = this.OrderManager.SubmitVisitorOrder(currentCart.Result);
                if (managerResponse.ServiceProviderResult.Success || !managerResponse.ServiceProviderResult.SystemMessages.Any())
                {
                    model.Temp           = managerResponse.Result;
                    model.ConfirmationId = managerResponse.Result.TrackingNumber;
                    result.SetResult(model);

                    return(result);
                }

                result.SetErrors(managerResponse.ServiceProviderResult);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex, this);
                result.SetErrors(nameof(this.SubmitOrder), ex);
            }

            return(result);
        }
        public IHttpActionResult Submit(SubmitOrderModel data)
        {
            MobileStoreServiceEntities db = new MobileStoreServiceEntities();

            try
            {
                ORDER order = new ORDER();

                order.NAME       = data.user_info.name;
                order.ADDRESS    = data.user_info.address;
                order.PHONE      = data.user_info.phone;
                order.USERNAME   = data.user_info.username;
                order.ORDER_DATE = DateTime.Now;
                order.PAID       = 0;
                order.DELETED    = 0;
                db.ORDERS.Add(order);
                db.SaveChanges();

                if (CreateOrder(order, data) == false)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
            return(Ok());
        }
示例#3
0
        public IActionResult Checkout()
        {
            var cart  = _checkoutService.GetCart();
            var order = _checkoutService.CalculateOrder(cart);
            var model = new SubmitOrderModel {
                Order = order
            };

            return(View(model));
        }
 public void Post([FromBody] SubmitOrderModel value)
 {
     try
     {
         _orderService.SubmitOrder(value);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
示例#5
0
        public IActionResult Checkout(SubmitOrderModel model)
        {
            var cart = _checkoutService.CreateCart();

            if (!ModelState.IsValid)
            {
                var order = _checkoutService.CalculateOrder(cart);
                model.Order = order;
                return(View(model));
            }

            return(View("Confirm"));
        }
示例#6
0
        public ActionResult Submit(SubmitOrderModel model)
        {
            var orderRepository = new OrderRepository();
            var order           = new Order();

            order.Email = model.Email;
            foreach (var orderedDish in model.Dishes)
            {
                if (orderedDish.Quantity > 0)
                {
                    order.AddOrderDetail(orderedDish.Id, orderedDish.Quantity);
                }
            }

            var orderId = orderRepository.Save(order);

            return(Json(new { orderId, confirmLink = Url.Action("Confirm", new { id = orderId }) }));
        }
示例#7
0
        public async Task SubmitOrder(SubmitOrderModel model)
        {
            try
            {
                var orderModel = new Orders()
                {
                    CreatedDate   = DateTime.Now,
                    OrderStatus   = "Initiated",
                    TransactionId = Guid.NewGuid().ToString()
                };
                await _orderRepository.AddOrder(orderModel);

                _orderEventProducer.SendPlaceOrderMessages(orderModel.TransactionId, model);
                _smsService.SendSms("Your Order Has been Submitted Sucssesfully");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
 public async Task SendPlaceOrderMessages(string transactionId, SubmitOrderModel model)
 {
     _kafkaService.SendEvent(KafkaConstants.Hotel_Topic, KafkaConstants.Place_Hotel_Order_Event,
                             _messageSerializer.Serialize(new PlaceHotelOrderMessage()
     {
         TransactionId        = transactionId,
         HotelReservationDate = model.HotelReservationDate
     }));
     _kafkaService.SendEvent(KafkaConstants.Flight_Topic, KafkaConstants.Place_Flight_Order_Event,
                             _messageSerializer.Serialize(new PlaceFlightOrderMessage()
     {
         TransactionId = transactionId,
         FlightNumber  = model.FlightNumber
     }));
     _kafkaService.SendEvent(KafkaConstants.Car_Topic, KafkaConstants.Place_Car_Order_Event,
                             _messageSerializer.Serialize(new PlaceCarOrderMessage()
     {
         TransactionId = transactionId,
         CarRentPrice  = model.CarRentPrice
     }));
 }
        private bool CreateOrder(ORDER order, SubmitOrderModel data)
        {
            MobileStoreServiceEntities db = new MobileStoreServiceEntities();
            double orderTotal             = 0;

            try
            {
                // Iterate over the items in the cart,
                // adding the order details for each
                foreach (var item in data.order_info)
                {
                    PRODUCT product = db.PRODUCTs.First(x => x.PRODUCT_ID == item.product_id);
                    product.QUANTITY -= item.quantity;
                    var orderDetail = new ORDER_DETAILS
                    {
                        PRODUCT_ID = item.product_id,
                        ORDER_ID   = order.ORDER_ID,
                        UNIT_PRICE = item.unit_price,
                        QUANTITY   = item.quantity
                    };
                    // Set the order total of the shopping cart
                    orderTotal += (item.quantity * item.unit_price);

                    db.ORDER_DETAILS.Add(orderDetail);
                }
                // Set the order's total to the orderTotal count
                ORDER nOrder = db.ORDERS.First(o => o.ORDER_ID == order.ORDER_ID);
                nOrder.TOTAL = orderTotal;

                // Save the order
                db.SaveChanges();
            }
            catch
            {
                return(false);
            }
            // Return the OrderId as the confirmation number
            return(true);
        }