public int CreateOrderDetail(OrderDetail orderDetail) { List <OrderDetail> orderDetails = _context.OrderDetails.ToList(); OrderDetail FindOrderDetail = orderDetails.Find(o => o.OrderId == orderDetail.OrderId && o.ProductId == orderDetail.ProductId); Product product = _context.Products.FirstOrDefault(p => p.Id == orderDetail.ProductId); if (orderDetails.Contains(FindOrderDetail)) { FindOrderDetail.Quantity += orderDetail.Quantity; FindOrderDetail.Total += Bill(product.Price, orderDetail.Quantity, orderDetail.Discount); _context.Update(FindOrderDetail); } else { orderDetail.Total = Bill(product.Price, orderDetail.Quantity, orderDetail.Discount); _context.Add(orderDetail); } return(_context.SaveChanges()); }
public int CreateProduct(CreateProductView productView) { foreach (var item in _context.Products) { if (item.Name != productView.Name) { Product product = new Product() { Name = productView.Name, Price = productView.Price, CreateAt = productView.CreateAt, CategoryId = productView.CategoryId, AvataPath = UploadedFile(productView.Avata) }; _context.Add(product); return(_context.SaveChanges()); } } return(0); }
public int CreateCategory(Category category) { _context.Add(category); return(_context.SaveChanges()); }
public int CreateOrder(Order order) { _context.Add(order); return(_context.SaveChanges()); }