Пример #1
0
        public async Task <AddProductPayload> AddProductAsync(
            AddProductInput input,
            [Service] OMSOrdersContext context)
        {
            if (string.IsNullOrWhiteSpace(input.ProductName))
            {
                _logger.LogError("invalid input {@input}", input);
                throw new Exception("Bad request");
            }

            var product = new Product
            {
                ProductName = input.ProductName,
                Cost        = Convert.ToDecimal(input.Cost)
            };

            _logger.LogDebug("adding product {@input}", input);

            context.Products.Add(product);
            await context.SaveChangesAsync();

            return(new AddProductPayload(new GQLModels.Product
            {
                ProductName = input.ProductName,
                Cost = input.Cost
            }));
        }
Пример #2
0
 public async Task <List <OrderHeader> > GetOrderHeaders([Service] OMSOrdersContext context, long customerId) =>
 //await Expression.TryCatch(Expression.Block(typeof(void), context .OrderHeaders.ToListAsync()), Expression.Catch(typeof(System.Exception), null));
 await context
 .OrderHeaders
 .Where(w => w.CustomerId == customerId)
 .OrderBy(o => o.OrderedDate)
 .ToListAsync();
Пример #3
0
        public async Task <AddOrderPayload> AddOrderAsync(
            AddOrderInput input,
            [Service] OMSOrdersContext context)
        {
            if (string.IsNullOrWhiteSpace(input.Email) || string.IsNullOrWhiteSpace(input.UserName) ||
                string.IsNullOrWhiteSpace(input.OrderName) || string.IsNullOrWhiteSpace(input.Address))
            {
                _logger.LogError("invalid input {@input}", input);
                throw new Exception("Bad request");
            }

            var order = new Orders
            {
                OrderName   = input.OrderName,
                Email       = input.Email,
                PhoneNumber = input.PhoneNumber,
                UserName    = input.UserName,
                Address     = input.Address,
                ProductId   = input.ProductId
            };

            _logger.LogDebug("adding order {@input}", input);

            context.Orders.Add(order);
            await context.SaveChangesAsync();

            return(new AddOrderPayload(new GQLModels.Orders
            {
                OrderName = input.OrderName,
                Email = input.Email,
                PhoneNumber = input.PhoneNumber,
                UserName = input.UserName,
                Address = input.Address
            }));
        }
Пример #4
0
 public async Task <List <Order> > GetOrders([Service] OMSOrdersContext context, long customerId)
 {
     try
     {
         return(Convert(await GetOrderHeaders(context, customerId)));
     }
     catch (System.Exception ex)
     {
         //ExceptionHandler(ex);
         return(null);
     }
 }
Пример #5
0
        public IQueryable <Product> GetProducts([Service] OMSOrdersContext context)
        {
            _logger.LogDebug("getting products details");
            var products = context.Products.Select(a => new Product
            {
                ProductName = a.ProductName,
                Cost        = a.Cost,
                ProductId   = a.ProductId
            });

            return(products);
        }
Пример #6
0
        public IList <Orders> GetOrders([Service] OMSOrdersContext context)
        {
            _logger.LogDebug("getting order details");
            var query = context.Orders.Select(a => new Orders
            {
                Address     = a.Address,
                PhoneNumber = a.PhoneNumber,
                OrderName   = a.OrderName,
                UserName    = a.UserName,
                ProductId   = a.ProductId,
                Email       = a.Email,
                ProductName = a.Product.ProductName,
                Cost        = a.Product.Cost
            });

            return(query.ToList());
        }
Пример #7
0
        public OrderSummery GetOrderSummery([Service] OMSOrdersContext context, int orderId)
        {
            if (orderId == 0)
            {
                _logger.LogError("Invalid OrderId");
                throw new InvalidOperationException("Invalid OrderId");
            }
            _logger.LogDebug("getting order summery details by {orderId}", orderId);
            var orderData = (from order in context.Orders
                             join product in context.Products on order.ProductId equals product.ProductId
                             select new { order, product })
                            .FirstOrDefault(a => a.order.OrderId == orderId);

            return(new OrderSummery
            {
                OrderDate = orderData.order.OrderDate,
                OrderId = orderData.order.OrderId,
                OrderName = orderData.order.OrderName,
                Cost = orderData.product.Cost,
                ProductName = orderData.product.ProductName
            });
        }
Пример #8
0
 public async Task <List <OrderDetailLine> > GetOrderDetailLines([Service] OMSOrdersContext context, long orderDetailId) =>
 await context
 .OrderDetailLines
 .Where(o => o.OrderDetailId == orderDetailId)
 .OrderBy(i => i.OrderDetailLineId)
 .ToListAsync();