public async Task <IActionResult> CreateOrderDetail([FromBody] OrderImportDetailsViewModel detail) { if (!ModelState.IsValid) { return(Ok(new Response { IsError = true, Status = 400, Message = "Sai dữ liệu đầu vào" })); } OrderImportGoodsDetails orderdetail = new OrderImportGoodsDetails { OrderId = detail.OrderId, ProductId = detail.ProductId, UnitPrice = 0, Quantity = 0 }; _context.OrderImportGoodsDetails.Add(orderdetail); await _context.SaveChangesAsync(); return(Ok(new Response { Status = 204 })); }
public async Task <IActionResult> QuickAddProduct(QuickAddProductViewModel productAdd) { int orderId = productAdd.OrderId; var product = new Products { ProductName = productAdd.ProductName, CategoryId = productAdd.CategoryId, CreateAt = DateTime.Now, Description = "", Discontinued = true, DisplayIndex = false, Discount = 0, Stock = 0, UnitPrice = 0, Summary = "", Guarantee = 0 }; await _context.Products.AddAsync(product); await _context.SaveChangesAsync(); if (productAdd.OrderId > 0) { var orderDetail = new OrderImportGoodsDetails { OrderId = productAdd.OrderId, ProductId = product.ProductId, Quantity = productAdd.Quantity, UnitPrice = productAdd.UnitPrice }; _context.OrderImportGoodsDetails.Add(orderDetail); await _context.SaveChangesAsync(); } else { OrdersImportGoods orders = new OrdersImportGoods { OrderDate = DateTime.Now, SupplierId = productAdd.SupplierId, UserId = productAdd.UserId, TotalPrice = 0 }; orders.OrderImportGoodsDetails.Add(new OrderImportGoodsDetails { ProductId = product.ProductId, Quantity = productAdd.Quantity, UnitPrice = productAdd.UnitPrice }); _context.OrdersImportGoods.Add(orders); await _context.SaveChangesAsync(); orderId = orders.OrderId; } return(Ok(new Response { Status = 201, Module = new { orderId, product.ProductId } })); }