public int UpdateLine(Models.ResOrderItemView data) { try { var _data = this.GetByOrderItemId2(data.OrderItemId); //this.MapView2Table(data, _data); _data.OrderId = data.OrderId; _data.ItemId = data.ItemId; _data.Quantity = data.Quantity; //_data.QuantityProcess = _data.QuantityProcess;//tạm thời khi order coi như bếp làm xong _data.Price = data.Price; _data.Amount = data.Amount; _data.ItemNote = data.ItemNote; this._db.Entry(_data).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); return(_data.OrderItemId); } catch (Exception) { throw; } }
public int InsertLine(Models.ResOrderItemView data) { try { var _data = new Models.ResOrderItem(); //this.MapView2Table(data, _data); _data.OrderId = data.OrderId; _data.ItemId = data.ItemId; _data.Quantity = data.Quantity; _data.QuantityProcess = 0;// _data.Quantity;//tạm thời khi order coi như bếp làm xong _data.Price = data.Price; _data.Amount = data.Amount; _data.ItemNote = data.ItemNote; _data.CreateDate = data.CreateDate; this._db.ResOrderItems.Add(_data); this._db.SaveChanges(); return(_data.OrderItemId); } catch (Exception) { throw; } }
public ActionResult ChangeTable(int TableId, int TableId2) { // TODO: Add insert logic here try { if (TableId2 > 0) { var table2 = _dataobject._db.ResTables.Where(m => m.TableId == TableId2).SingleOrDefault(); //ViewBag.TableId2 = TableId2; var model = _dataobject.GetTable(TableId); if (model == null) { throw new Exception("Phải nhập bàn cần chuyển"); } var model2 = _dataobject.GetTable(TableId2); if (model2 == null) { //trường hợp bàn 1 active bàn 2 không active model2 = _dataobject.GetNew(null, TableId); _dataobject.MapView2Table(model, model2); model2.ResOrderItemViews = new System.Collections.ObjectModel.Collection <Models.ResOrderItemView>(); model2.ResOrderItemViewz = new System.Collections.ObjectModel.Collection <int>(); foreach (var item in model.ResOrderItemViews) { var _item = new Models.ResOrderItemView(); //_dataobject.MapView2Table(_item, item); //_item.OrderId = model2.OrderId; _item.ItemId = item.ItemId; _item.Quantity = item.Quantity; _item.QuantityProcess = item.Quantity;//tạm thời khi order coi như bếp làm xong _item.Price = item.Price; _item.Amount = item.Amount; _item.ItemNote = item.ItemNote; _item.CreateDate = item.CreateDate; model2.ResOrderItemViews.Add(_item); model2.ResOrderItemViewz.Add(0); } model.OrderStatusId = -1; model.Note = string.Format("Chuyển sang bàn {0}", table2.Name); model2.TableId = TableId2; _dataobject.Insert(model2); } else { //trường hợp 2 bàn đang active //trường hợp bàn 1 active bàn 2 không active var model3 = _dataobject.GetNew(null, TableId2); _dataobject.MapView2Table(model2, model3); model3.ResOrderItemViewz = new System.Collections.ObjectModel.Collection <int>(); foreach (var item in model2.ResOrderItemViews) { var _item = new Models.ResOrderItemView(); //_dataobject.MapView2Table(_item, item); _item.OrderId = item.OrderId; _item.OrderItemId = item.OrderItemId; _item.ItemId = item.ItemId; _item.Quantity = item.Quantity; _item.QuantityProcess = item.Quantity;//tạm thời khi order coi như bếp làm xong _item.Price = item.Price; _item.Amount = item.Amount; _item.ItemNote = item.ItemNote; _item.CreateDate = item.CreateDate; model3.ResOrderItemViews.Add(_item); model3.ResOrderItemViewz.Add(item.OrderItemId); } foreach (var item in model.ResOrderItemViews) { var _item = new Models.ResOrderItemView(); //_dataobject.MapView2Table(_item, item); _item.OrderId = model2.OrderId; _item.ItemId = item.ItemId; _item.Quantity = item.Quantity; _item.QuantityProcess = item.Quantity;//tạm thời khi order coi như bếp làm xong _item.Price = item.Price; _item.Amount = item.Amount; _item.ItemNote = item.ItemNote; _item.CreateDate = item.CreateDate; model3.ResOrderItemViews.Add(_item); model3.ResOrderItemViewz.Add(0); } model3.OrderSubtotal = model3.ResOrderItemViews.Sum(m => m.Amount); if (model2.OrderDiscountPercentage != 0) { model3.OrderDiscount = model3.OrderSubtotal * model2.OrderDiscountPercentage; } model3.OrderQuantity = model3.ResOrderItemViews.Sum(m => m.Quantity); model3.OrderQuantityProcess = model3.ResOrderItemViews.Sum(m => m.QuantityProcess); model3.OrderTotal = model3.OrderSubtotal - model3.OrderDiscount; //model2.TableId = TableId2; model.OrderStatusId = -1; model.Note = string.Format("Chuyển sang bàn {0}", table2.Name); _dataobject.Update(model3); } } //return RedirectToAction("Index", "ResHome"); return(PartialView("UpdateSuccess", TableId2)); } catch (Exception ex) { WebApp.Areas.Accounting.Services.GlobalErrors.Parse(ModelState, _dataobject.Errors, ex); return(PartialView(this._updateview, TableId)); } }