示例#1
0
        private void PostValidOrderTest()
        {
            OrdersController ordersController = CreateFakeOrdersController(_users[0]);
            PostOrderModel   postOrderModel   = new PostOrderModel(2, new List <OrderProductModel>()
            {
                new OrderProductModel(2, 1),
                new OrderProductModel(3, 10),
                new OrderProductModel(4, 100)
            });

            //Add valid order
            var response = ordersController.PostOrder(postOrderModel);

            Assert.IsType <OkObjectResult>(response.Result);

            //Check same order is posted
            GetOrderModel getOrderModel = ((GetOrderModel)((OkObjectResult)response.Result).Value);
            Order         postedOrder   = _ordersService.GetOrderById(getOrderModel.Id);

            Assert.Equal(getOrderModel.Id, postedOrder.Id);
            Assert.Equal(postOrderModel.RestaurantId, postedOrder.RestaurantId);

            var orderProductPairs = postedOrder.OrdersProducts.Zip(postOrderModel.Products, (op1, op2) => new { poOrderProduct = op1, opmOrderProduct = op2 });

            foreach (var orderProductPair in orderProductPairs)
            {
                Assert.Equal(orderProductPair.poOrderProduct.ProductId, orderProductPair.opmOrderProduct.ProductId);
                Assert.Equal(orderProductPair.poOrderProduct.Quantity, orderProductPair.opmOrderProduct.Quantity);
            }
        }
示例#2
0
 /// <summary>
 /// 拉取配送单信息
 /// </summary>
 /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
 /// <param name="data">请求数据</param>
 /// <param name="timeOut">代理请求超时时间(毫秒)</param>
 /// <returns></returns>
 public static GetOrderJsonResult GetOrder(string accessTokenOrAppId, GetOrderModel data, int timeOut = Config.TIME_OUT)
 {
     return(WxOpenApiHandlerWapper.TryCommonApi(accessToken =>
     {
         var urlFormat = Config.ApiMpHost + "/cgi-bin/express/local/business/order/get?access_token={0}";
         return CommonJsonSend.Send <GetOrderJsonResult>(accessToken, urlFormat, data, timeOut: timeOut);
     }, accessTokenOrAppId));
 }
示例#3
0
        public async Task GetAsyncByIdTest()
        {
            int           orderId  = 1;
            GetOrderModel expected = CreateGetOrderModel();

            SetupOrderRepositoryGetAsyncMock(orderId, expected);

            GetOrderModel actual = await orderService.GetAsync(orderId);

            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public async Task <CustomResponse> Get(Guid id)
        {
            OrderDto order = await _unitOfWork.OrderRepository.FindAsync(id);

            if (order == null)
            {
                return(_responsMessages.OrderNotFound);
            }

            GetOrderModel model = _mapper.Map <GetOrderModel>(order);

            return(new OkResponse(model));
        }
示例#5
0
        public async Task <IActionResult> ChangeOrder(GetOrderModel model)
        {
            var order = await db.GetOrderAsync(model.Order.Id);

            // Get user
            var user = await db.GetUserAsync(order.UserId);

            // Send mail about changes in status to this user
            await NotificationService.Service.SendOrderNotificationAsync(user.Email, order, model.Status);

            // Change and save order
            await db.ChangeStatusAsync(model.Order.Id, model.Status);

            return(RedirectToAction("PersonalArea", "Home"));
        }
示例#6
0
        public async Task <IActionResult> GetOrder(int id)
        {
            var order = await db.GetOrderAsync(id);

            if (order.UserId != (int)TempData.Peek("id") && "admin" != (string)TempData.Peek("role"))
            {
                return(RedirectToAction("Error",
                                        new ErrorViewModel()
                {
                    ActionName = "GetOrders",
                    RequestInfo = $"You dont have permissions."
                }));
            }

            if (order == null)
            {
                return(RedirectToAction("Error", "Home",
                                        new ErrorViewModel()
                {
                    ActionName = "Index",
                    RequestInfo = $"Order with id = {id} doesn't exist."
                }));
            }

            // Get sub orders
            order.SubOrders = await db.GetSubOrdersAsync(order.Id);

            // Create list of subOrders
            var list = new List <Tuple <ProductInfo, int> >();

            // Fill sub orders info
            foreach (var subOrder in order.SubOrders)
            {
                var product = await db.GetProductInfoAsync(subOrder.ProductId);

                list.Add(Tuple.Create(product, subOrder.Count));
            }
            // Create and return model
            var model = new GetOrderModel()
            {
                Order = order, SubOrders = list, Status = order.StatusInfo, Role = (string)TempData.Peek("role")
            };

            return(View(model));
        }
示例#7
0
        public override Task <GetOrdersResponse> GetOrders(GetOrdersRequest request, ServerCallContext context)
        {
            var service = new BlazorInsider.App.Services.DatabaseService();
            var orders  = service.GetOrders();

            var result = new GetOrdersResponse();

            foreach (var item in orders)
            {
                var order = new GetOrderModel()
                {
                    OrderID     = item.OrderId,
                    Description = item.Description,
                    Quantity    = item.Quantity,
                    Status      = item.Status,
                    Total       = item.Total
                };
                result.GetOrderModels.Add(order);
            }

            return(Task.FromResult(result));
        }
示例#8
0
 /// <summary>
 /// 拉取配送单信息
 /// </summary>
 /// <param name="accessTokenOrAppId">AccessToken或AppId(推荐使用AppId,需要先注册)</param>
 /// <param name="data">请求数据</param>
 /// <param name="timeOut">代理请求超时时间(毫秒)</param>
 /// <returns></returns>
 public static async Task <GetOrderJsonResult> GetOrderAsync(string accessTokenOrAppId, GetOrderModel data, int timeOut = Config.TIME_OUT)
 {
     return(await WxOpenApiHandlerWapper.TryCommonApiAsync(async accessToken =>
     {
         var urlFormat = Config.ApiMpHost + "/cgi-bin/express/local/business/order/get?access_token={0}";
         return await CommonJsonSend.SendAsync <GetOrderJsonResult>(accessToken, urlFormat, data, timeOut: timeOut);
     }, accessTokenOrAppId).ConfigureAwait(false));
 }
示例#9
0
 private void SetupOrderRepositoryGetAsyncMock(int id, GetOrderModel getOrderModel)
 => orderRepositoryMock
 .Setup(repository => repository.GetAsync(id))
 .ReturnsAsync(getOrderModel);
        public IActionResult GetOrder([FromQuery] GetOrderModel getOrderModel)
        {
            var order = ordersRepository.Find(getOrderModel.OrderId);

            return(Ok(order));
        }