예제 #1
0
        public async Task <IActionResult> GetOrdersAsync()
        {
            var result = await orderProvider.GetOrdersAsync();

            if (result.Success)
            {
                return(Ok(result.Orders));
            }
            return(NotFound());
        }
예제 #2
0
        public async Task <IActionResult> GetOrderAsync(int customerId)
        {
            var result = await orderProvider.GetOrdersAsync(customerId);

            if (result.IsSucess)
            {
                return(Ok(result.Orders));
            }
            return(NotFound());
        }
예제 #3
0
        public async Task <IActionResult> GetOrdersAsync(int customerId)
        {
            var result = await orderProvider.GetOrdersAsync(customerId);

            if (result.IsSuccess)
            {
                return(Ok(result.Item2));
            }
            return(NoContent());
        }
        public async Task <(ResultStatus Status, IEnumerable <Top5Product> Products)> Get5TopProductsAsync()
        {
            try
            {
                var filters = new Dictionary <string, string> {
                    { OrderFilters.Status, OrderStatus.InProgress.Name }
                };

                var orders = await _orderProvider.GetOrdersAsync(filters);

                if (orders == null)
                {
                    return(ResultStatus.UnknownError, null);
                }

                var topProductNos = orders.SelectMany(order => order.Lines)
                                    .GroupBy(line => line.MerchantProductNo)
                                    .Select(group => new
                                            { ProductNo = group.Key, TotalQuantity = group.Select(line => line.Quantity).Sum() })
                                    .OrderByDescending(x => x.TotalQuantity)
                                    .Take(5).ToList();

                if (!topProductNos.Any())
                {
                    return(ResultStatus.Success, Enumerable.Empty <Top5Product>());
                }

                var products = await _productProvider.GetProductsAsync(new Dictionary <string, string>());

                if (products == null)
                {
                    return(ResultStatus.UnknownError, null);
                }

                var result = products.Join(topProductNos, product => product.MerchantProductNo, top => top.ProductNo,
                                           (product, top) => new Top5Product {
                    Product = product, TotalQuantity = top.TotalQuantity
                })
                             .OrderByDescending(product => product.TotalQuantity);

                return(ResultStatus.Success, result);
            }
            catch (Exception e)
            {
                //log ex
                return(ResultStatus.UnknownError, null);
            }
        }
        public async Task <(ResultStatus Status, IEnumerable <DataObjects.Order.Order> Orders)> GetOrdersAsync(
            OrderStatus orderStatus)
        {
            try
            {
                var filters = new Dictionary <string, string>();
                if (orderStatus != OrderStatus.Empty)
                {
                    filters.Add(OrderFilters.Status, orderStatus.Name);
                }

                var orders = await _orderProvider.GetOrdersAsync(filters);

                return(orders == null
                    ? (ResultStatus.UnknownError, null)
                    : (ResultStatus.Success, orders.OrderBy(o => o.Id)));
            }
            catch (Exception)
            {
                //log ex
                return(ResultStatus.UnknownError, null);
            }
        }