public C_Order Convert(Order order) { C_Order cOrder = new C_Order(); cOrder.id = order.Id; //cOrder.userId = order.User.Id; //cOrder.C_OrderItems cOrder.money = order.Money; cOrder.timestamp = order.Timestamp; return cOrder; }
public Order Convert(C_Order cOrder) { Order order = new Order(); order.Id = cOrder.id; //order.User = //order.Items = cOrder.C_OrderItems.ToList(); order.Money = (decimal)cOrder.money; order.Timestamp = cOrder.timestamp; return order; }
public bool InsertOrderFromUser(int userId, Address address, Visa visa) { bool completed = false; using (var context = Config.context) { try { C_Order order = new C_Order(); // Get products in baskets and add them to order var data = context.C_Basket.Where(c => c.userId == userId).Select(c => new { c.C_Product }); foreach (var item in data) { C_OrderItem orderItem = new C_OrderItem(); orderItem.C_Product = item.C_Product; order.C_OrderItem.Add(new C_OrderItem()); } // Remove products in basket var baskets = context.C_Basket.Where(i => i.userId == userId); foreach (var item in baskets) context.C_Basket.Remove(item); // Setup order before adding it to database order.userId = userId; order.timestamp = DateTime.Now; // Setup address // Setup payment context.C_Order.Add(order); context.SaveChanges(); completed = true; } catch (Exception ex) { // log here } } return completed; }