예제 #1
0
        public void Execution_deletes_order_and_associated_order_items_state_based()
        {
            var order = new Order()
            {
                OrderDate = DateTime.Now
            };
            var orderRepo = new OrderRepository(Mock.Of <ICustomerDataProxy>(), Mock.Of <IOrderItemDataProxy>());

            orderRepo.Clear();
            order = orderRepo.Insert(order);
            var orderItemRepo = new OrderItemRepository();

            orderItemRepo.Clear();
            orderItemRepo.Insert(new OrderItem {
                OrderID = order.ID, OrderStatusID = OrderStatusConstants.PENDING_STATUS
            });
            orderItemRepo.Insert(new OrderItem {
                OrderID = order.ID, OrderStatusID = OrderStatusConstants.SUBMITTED_STATUS
            });
            orderItemRepo.Insert(new OrderItem {
                OrderID = order.ID, OrderStatusID = OrderStatusConstants.BACK_ORDERED_STATE
            });
            orderItemRepo.Insert(new OrderItem {
                OrderID = 2, OrderStatusID = OrderStatusConstants.PENDING_STATUS
            });
            var orderItemService = new OrderItemService(orderItemRepo, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemDataProxy>(), new TransactionContextStub());

            var command = new DeleteOrderCommand(order.ID, orderRepo, orderItemService, new TransactionContextStub());

            command.Execute();
            orderRepo.GetAll().ShouldBeEmpty();
            orderItemRepo.GetAll().Count().ShouldBe(1);
        }
예제 #2
0
        public void Execution_should_fail_when_order_is_associated_with_items_that_have_been_shipped_state_based()
        {
            var order = new Order()
            {
                OrderDate = DateTime.Now
            };
            var orderRepo = new OrderRepository(Mock.Of <ICustomerDataProxy>(), Mock.Of <IOrderItemDataProxy>());

            orderRepo.Clear();
            order = orderRepo.Insert(order);
            var orderItemRepo = new OrderItemRepository();

            orderItemRepo.Clear();
            orderItemRepo.Insert(new OrderItem()
            {
                OrderID = order.ID, OrderStatusID = OrderStatusConstants.PENDING_STATUS
            });
            2.Times(() => orderItemRepo.Insert(new OrderItem()
            {
                OrderID = order.ID, OrderStatusID = OrderStatusConstants.SHIPPED_STATUS
            }));
            var orderItemService = new OrderItemService(orderItemRepo, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemDataProxy>(), Mock.Of <ITransactionContext>());

            var command = new DeleteOrderCommand(order.ID, orderRepo, orderItemService, new TransactionContextStub());
            var result  = command.Execute();

            result.Success.ShouldBe(false);
            result.Errors.Count().ShouldBe(2);
        }
        public ActionResult PlaceOrder(string id)
        {
            /* Find the details of the customer placing the order*/
            DataContext dataContext = new DataContext();
            var         user        = dataContext.Users.ToList().Find(x => x.Email == HttpContext.User.Identity.Name);
            var         customer    = new Customer();

            /* Place the order */
            _orderRepository.Insert(new Order()
            {
                Email       = user.Email,
                dateCraeted = DateTime.Now,
                shipped     = false,
                status      = "Awaiting Payment",
                TotalPrice  = cart_Service.GetCartTotal(cart_Service.GetCartID())
            });

            var order = _orderRepository.GetAll() //db.Orders.ToList()
                        .FindAll(x => x.Email == user.Email)
                        .OrderByDescending(x => x.dateCraeted)
                        .FirstOrDefault();

            /* If the customer requests delivery, save order address */
            if (id == "deliver")
            {
                //   db.SaveChanges();
                try
                {
                    _orderAddressRepository.Insert(new OrderAddress()
                    {
                        OrderNo = order.OrderNo,
                        //  street_number = Convert.ToInt16(Session["street_number"].ToString()),
                        street = Session["street_name"].ToString(),
                        city   = Session["City"].ToString(),
                        // state = Session["State"].ToString(),
                        zipcode = Session["ZipCode"].ToString()
                                  // Country = Session["Country"].ToString(),

                                  //Building_Name = "",
                                  //Floor = "",
                                  //Contact_Number = "",
                                  //Comments = "",
                                  //Address_Type = ""
                    });
                }
                catch (Exception x)
                {
                    var m = x.Message;
                }
            }
            /* Migrate cart items to map as order items */
            //   order_Service.AddOrderItems(order, cart_Service.GetCartItems());
            var items = cart_Service.GetCartItems();

            foreach (var item in items)
            {
                var x = new OrderItem()
                {
                    Order_ID = order.OrderNo,
                    ItemCode = item.ItemdId,
                    quantity = item.quantity,
                    price    = item.price
                };


                //   ob.updateStock_bot(x.item_id, x.quantity);
                // db.OrderItems.Add(x);
                // db.SaveChanges();
                _orderItemRepository.Insert(x);
            }
            /* Empty the cart items */
            cart_Service.EmptyCart();
            /* Update Order Tracking Report */
            _orderTrackingRepository.Insert(new OrderTracking()
            {
                orderNo   = order.OrderNo,
                date      = DateTime.Now,
                status    = "Awaiting Payment",
                Recipient = ""
            });

            //Redirect to payment
            return(RedirectToAction("Payment", new { id = order.OrderNo }));
            // return RedirectToAction("Payment",new { id = order.OrderNo });
        }
예제 #4
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            Console.WriteLine("Sendo Importer - .Net Core Console App with SOLID principles");

            ICollectionCommand <List <Order> > sendoAPI = (ICollectionCommand <List <Order> >) new SendoApiRefractory(a =>
            {
                a.From = DateTime.Today.AddDays(-14);
                a.To   = DateTime.Now;
            });
            //SendoAPI sendoAPI = new SendoAPI();
            string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdG9yZUlkIjoiMzgyMDA5IiwiVXNlck5hbWUiOiIiLCJTdG9yZVN0YXR1cyI6IjIiLCJTaG9wVHlwZSI6IjAiLCJTdG9yZUxldmVsIjoiMCIsImV4cCI6MTU5NjY0OTk4MSwiaXNzIjoiMzgyMDA5IiwiYXVkIjoiMzgyMDA5In0.Bd1AqHjcLlYTXFkInlHbTY2vP_XTmQ40pQ_agk-1hjQ"; //await sendoAPI.GetToken();

            if (!string.IsNullOrEmpty(token))
            {
                await sendoAPI.Execute();

                IList <Order> orders = sendoAPI.Result;

                if (orders.Count > 0)
                {
                    OrderRepository     orderRepo     = new OrderRepository();
                    OrderItemRepository orderItemRepo = new OrderItemRepository();

                    foreach (Order order in orders)
                    {
                        int orderId = orderRepo.GetOrderIdByOrderNo(order.OrderNumber);

                        if (orderId > 0)
                        {
                            //update
                            if (orderRepo.Update(order))
                            {
                                Console.WriteLine("Updated order {0}", order.OrderNumber);
                            }
                            continue;
                        }
                        else
                        {
                            //insert new order
                            orderId = orderRepo.Insert(order);
                            if (orderId > 0)
                            {
                                Console.WriteLine("Inserted order {0}", order.OrderNumber);

                                //insert items
                                foreach (OrderItem orderItem in order.Items)
                                {
                                    orderItem.OrderId = orderId;
                                    orderItemRepo.Insert(orderItem);
                                }
                            }
                            else
                            {
                                //insert failed
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No new orders found");
                }
            }
            else
            {
                Console.WriteLine("Can not get token");
            }
        }
예제 #5
0
 public int Insert(OrderItem order_item)
 {
     return(_repository.Insert(order_item));
 }