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 })); }
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();
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 })); }
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); } }
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); }
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()); }
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 }); }
public async Task <List <OrderDetailLine> > GetOrderDetailLines([Service] OMSOrdersContext context, long orderDetailId) => await context .OrderDetailLines .Where(o => o.OrderDetailId == orderDetailId) .OrderBy(i => i.OrderDetailLineId) .ToListAsync();