public static CateringOrderDetail ToModel(this OrderRequest.OrderRequestItem viewmodel) { CateringOrderDetail model = new CateringOrderDetail(); model.CateringProductID = viewmodel.ID; model.Attributes = JsonConvert.SerializeObject(viewmodel.Attributes); model.Amount = viewmodel.Amount; return(model); }
private void MigrateOrdersAndDetails(DataContext db, MySqlConnection conn, DataSet set, MySqlDataAdapter adapter) { adapter.SelectCommand = new MySqlCommand("Select * from catering_orders", conn); adapter.Fill(set, "catering_orders"); foreach (DataRow entry in set.Tables["catering_orders"].Rows) { int seatID = Convert.ToInt32(entry["seat_id"]); if (db.Seat.FirstOrDefault(x => x.SeatNumber == seatID) == null) { Console.WriteLine("Skipping OrderDetail SeatID : {0} does not exist", Convert.ToInt32(entry["seat_id"])); continue; } var offsetID = TupleToId(db, Convert.ToInt32(entry["user_id"])); int lanID = Convert.ToInt32(entry["lan_id"]); var seat = db.Seat.FirstOrDefault(x => x.SeatNumber == seatID); var order = new CateringOrder() { Event = (from eve in db.Event where eve.EventTypeID == 1 && eve.Volume == lanID select eve).First(), UserID = offsetID, Seat = seat, OrderState = Convert.ToInt32(entry["complete_status"]), Registered = DateTime.Now }; Detail test = null; string json = @entry["details"].ToString(); var obj = JsonConvert.DeserializeObject <List <Detail> >(json); foreach (Detail det in obj) { test = det; var details = new CateringOrderDetail() { CateringOrder = order, CateringProductID = det.ID.Value, Amount = 1, Attributes = JsonConvert.SerializeObject(det.attributes), }; db.CateringOrderDetail.Add(details); } } db.SaveChanges(); }
public static BackendCateringOrderItem FromModel(this BackendCateringOrderItem viewmodel, CateringOrderDetail model) { var attr = JsonConvert.DeserializeObject <String[]>(model.Attributes); viewmodel.ID = model.ID; viewmodel.Name = model.CateringProduct.Name; viewmodel.Attributes = attr.ToList(); viewmodel.Amount = model.Amount; viewmodel.Price = model.CateringProduct.Price; return(viewmodel); }