public async Task<JsonResult> GetTable(GetTableViewModel model) { using(MrCyContext ctx = new MrCyContext()) { DeskInfo desk = await ctx.DeskInfo.Where(p => p.QRCode == model.qrCode).FirstOrDefaultAsync(); Session["qrCode"] = desk.QRCode; return Json(desk); } }
public async Task<JsonResult> GetSavedMenu(GetTableViewModel model) { SubmitViewModel tempMenu = (SubmitViewModel)Session["savedMenu"]; if(tempMenu == null) { using(MrCyContext ctx = new MrCyContext()) { DeskInfo desk = await ctx.DeskInfo.Where(p => p.QRCode == model.qrCode).FirstOrDefaultAsync(); DineTempInfo dineInfo = await ctx.DineTempInfo.Where(p => p.DeskID == desk.DeskId).FirstOrDefaultAsync(); if(dineInfo == null) { return Json(null); } HistoryMenuModel menuModel = new HistoryMenuModel() { BeginTime = dineInfo.BeginTime.ToString(), PriceAll = (double)dineInfo.Subtotal, Table = desk, Customer = (int)dineInfo.peoplecount, PayKind = dineInfo.PayKind, Results = new List<HistoryMenuDetail>() }; List<DineTempDetail> list = await ctx.DineTempDetail.Where(p => p.AutoID == dineInfo.AutoID).ToListAsync(); foreach(DineTempDetail menu in list) { MenuDetail md = await ctx.MenuDetail.Where(p => p.DisherId == menu.DisherID).FirstOrDefaultAsync(); HistoryMenuDetail newDetail = new HistoryMenuDetail() { DisherName = md.DisherName, DisherId = menu.DisherID, DisherPrice = menu.DisherPrice == null ? 0 : (double)menu.DisherPrice, DisherDiscount = (double)menu.SalesDiscount, Note = menu.Note, Ordered = (int)menu.DisherNum }; menuModel.Results.Add(newDetail); } return Json(menuModel); } } HistoryMenuModel menuModelSession = new HistoryMenuModel() { PriceAll = (double)tempMenu.PriceAll, SizeAll = tempMenu.SizeAll, Table = tempMenu.Table, Customer = tempMenu.Customer, PayKind = tempMenu.PayKind, Results = new List<HistoryMenuDetail>() }; foreach(SubmitMenuDetail menu in tempMenu.Results) { string note = ""; if(menu.Additional.Notes != null) { foreach(Note n in menu.Additional.Notes) { note += (n.Note1 + " "); } } menuModelSession.Results.Add(new HistoryMenuDetail() { DisherId = menu.DisherId, DisherName = menu.DisherName, DisherDiscount = menu.DisherDiscount, DisherPrice = menu.DisherPrice, Note = note, Ordered = menu.Additional.Ordered }); } return Json(menuModelSession); }