public Order CreateOrder(List <int> seatIds, int viewingId) { Order order = new Order(); order.CustomerName = "Unknown"; //_context.Add(ticket); order.Tickets = new List <Ticket>(); _context.Add(order); int numSaved = _context.SaveChanges(); foreach (int id in seatIds) { Ticket ticket = new Ticket(); ticket.Date = DateTime.Now; ticket.SeatId = id; ticket.ViewingId = viewingId; ticket.OrderId = order.OrderId; _context.Add(ticket); } return(order); }
public Order CreateOrder(List <int> seatIds, int viewingId, string userName) { User user = _context.Users.FirstOrDefault(u => u.UserName == userName); Order order = new Order(); order.Tickets = new List <Ticket>(); _context.Add(order); order.UserId = user.UserId; order.User = user; int numSaved = _context.SaveChanges(); foreach (int id in seatIds) { Ticket ticket = new Ticket(); ticket.Date = DateTime.Now; ticket.SeatId = id; ticket.ViewingId = viewingId; ticket.OrderId = order.OrderId; _context.Add(ticket); } return(order); }