Ejemplo n.º 1
0
		public async Task<JsonResult> GetHistoryMenu(GetHistoryMenuViewModel model) {
			using(MrCyContext ctx = new MrCyContext()) {
				HistoryMenuModel menuModel;

				DineInfoHistory dineInfo = await ctx.DineInfoHistory.Where(p => p.CheckID == model.CheckID).FirstOrDefaultAsync();
				DineInfo dineInfo2 = await ctx.DineInfo.Where(p => p.CheckID == model.CheckID).FirstOrDefaultAsync();
				if(dineInfo != null) {
					DeskInfo desk = await ctx.DeskInfo.Where(p => p.DeskId == dineInfo.DeskID).FirstOrDefaultAsync();
					menuModel = new HistoryMenuModel() {
						CheckID = dineInfo.CheckID,
						BeginTime = dineInfo.BeginTime.ToString(),
						PriceAll = (double)dineInfo.Subtotal,
						Table = desk,
						Customer = (int)dineInfo.ClientNum,
						PayKind = dineInfo.PayKind,
						Results = new List<HistoryMenuDetail>()
					};
				}
				else {
					if(dineInfo2 == null) {
						return Json(null);
					}
					DeskInfo desk = await ctx.DeskInfo.Where(p => p.DeskId == dineInfo2.DeskID).FirstOrDefaultAsync();
					menuModel = new HistoryMenuModel() {
						CheckID = dineInfo2.CheckID,
						BeginTime = dineInfo2.BeginTime.ToString(),
						PriceAll = (double)dineInfo2.Subtotal,
						Table = desk,
						Customer = (int)dineInfo2.ClientNum,
						PayKind = dineInfo2.PayKind,
						Results = new List<HistoryMenuDetail>()
					};
				}



				if(dineInfo != null) {
					List<DineDetailHistory> list = await ctx.DineDetailHistory.Where(p => p.CheckID == dineInfo.CheckID).ToListAsync();
					foreach(DineDetailHistory 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);
					}
				}
				else {
					List<DineDetail> list2 = await ctx.DineDetail.Where(p => p.CheckID == dineInfo2.CheckID).ToListAsync();
					foreach(DineDetail menu in list2) {
						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);
			}
		}
Ejemplo n.º 2
0
		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);
		}