public bool SaveOrder(Order order, string userId) { bool result = false; using (var transaction = _dbContext.Database.BeginTransaction()) { try { var customer = _dbContext.ApplicationUsers.Where(a => a.Id == userId).FirstOrDefault(); order.Customer = customer; order.OrderDate = DateTime.UtcNow; _dbContext.Orders.Add(order); _dbContext.AddRange(order.OrderDetails); _dbContext.SaveChanges(); transaction.Commit(); if (order.OrderId > 0) { result = true; } } catch (Exception) { transaction.Rollback(); } } return(result); }