public void Create03(OrderCreateDTO03 item) { var order = _mapper.Map <Order>(item); _context.Add(order); //aqui ele tenta gravar o produto existente e dá erro porq o id já existe _context.SaveChanges(); foreach (var product in item.Products) { var orderProduct = new OrderProduct(order.Id, product.Id); _context.Add(orderProduct); _context.SaveChanges(); } }
public void Create03(OrderCreateDTO03 item) { var order = _mapper.Map <Order>(item); _context.Add(order); _context.SaveChanges(); foreach (var product in item.Products) { var orderProduct = new OrderProduct(order.Id, product.Id); _context.Add(orderProduct); _context.SaveChanges(); } }