예제 #1
0
        public async Task <IActionResult> CreateOrderAsync(string cardNum)
        {
            if (cardNum.Length == 0)
            {
                return(View());
            }
            PaymentMethod p     = new PaymentMethod(cardNum);
            User          u     = _userClient.GetCurrentUser();
            Order         order = new Order(u.Id, p);

            order.AddOrderItems(u.GetCart().GetOrderItems());
            u.GetCart().RemoveAll();
            await _orderClient.CreateOrder(order);

            await _userClient.UpdateAsync(u);

            return(View("Success"));
        }
예제 #2
0
        public async Task <IActionResult> CreateOrderAsync(string cardNum)
        {
            if (cardNum.Length == 0)
            {
                return(View());
            }
            PaymentMethod p     = new PaymentMethod(cardNum);
            User          u     = _userClient.GetCurrentUser();
            Order         order = new Order(u.Id, p);

            order.AddOrderItems(u.GetCart().GetOrderItems());
            u.GetCart().RemoveAll();
            Order nOrder = await _orderClient.CreateOrder(order);

            await _userClient.UpdateAsync(u);

            _logClient.SaveLog(u.Username, u.Username + " create order successfully! The order number is: " + nOrder.Id);
            return(View("Success"));
        }
예제 #3
0
        public JsonResult Create(List <OrderDetails> orderDetails, Customer customer)
        {
            try
            {
                customer.Gender       = "Male";
                customer.IdentityCard = "887799445511";
                customer.Address      = "HCM";
                customer.DateOfBirth  = DateTime.Now;
                var customerCreated = _customerClient.Create(customer);
                var empl            = _employeeClient.GetEmployee(Convert.ToInt32(Session["UserId"]));

                var order = new Order
                {
                    Customer     = customerCreated.Id,
                    Seller       = empl.Id,
                    OrderDate    = DateTime.Now,
                    OrderDetails = orderDetails,
                };

                var orderCreated = _orderClient.CreateOrder(order);

                foreach (var item in orderDetails)
                {
                    var orderDetail = new OrderDetails
                    {
                        OrderId   = orderCreated.Id,
                        ProductId = item.ProductId,
                        Quantity  = item.Quantity,
                    };

                    var detailsCreated = _orderClient.CreateOrderDetail(orderDetail);
                }

                return(Json(new { url = Url.Action("UserProfile", "Employee") }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { url = Url.Action("Index", "Home") }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #4
0
        public async Task WorkFlowTests()
        {
            //Arrange CREATE
            var orderModel = _fixture.Create <OrderModel>();
            var createdId  = orderModel.Id;

            //Act   CREATE
            var retrunModel = await _client.CreateOrder(orderModel);

            //Assert CREATE
            Assert.AreNotEqual(createdId, retrunModel.Id);

            //Act GET
            var order = await _client.GetOrder(retrunModel.Id);

            //Assert GET
            Assert.AreNotEqual(retrunModel, order);

            //Arrange UPDATE
            var oldName = order.CustomerName;

            order.CustomerName = Guid.NewGuid().ToString();

            //Act UPDATE
            await _client.UpdateOrder(order);

            order = await _client.GetOrder(order.Id);

            //Assert UPDATE
            Assert.AreNotEqual(oldName, order.CustomerName);

            //Act DELETE
            await _client.DeleteOrder(order.Id);

            order = await _client.GetOrder(order.Id);

            //Assert DELETE
            Assert.IsNull(order);
        }