public Models.ResOrderView GetNew(int?id, int tableid) { if (id != null) { return(GetById(id ?? 0)); } var model = new Models.ResOrderView() { OrderDate = DateTime.Now, CreatedDateTime = DateTime.Now, OrderStatusId = 1 }; var postable = this._db.ResTables.SingleOrDefault(m => m.TableId == tableid); if (postable != null) { model.TableId = postable.TableId; model.TableName = postable.Name; } return(model); }
public int Update(Models.ResOrderView data) { try { if (data.ResOrderItemViewz == null) { throw new Exception("Phải nhập chi tiết!"); } var countline = data.ResOrderItemViewz.Where(m => m != -1).Count(); if (countline == 0) { throw new Exception("Phải nhập chi tiết!"); } this.Validate(data); var _data = this.GetById2(data.OrderId); data.ModifiedBy = GlobalVariant.GetAppUser().UserID; data.ModifiedDateTime = DateTime.Now; data.CreatedBy = _data.CreatedBy; data.CreatedDateTime = _data.CreatedDateTime; this.MapView2Table(data, _data); this._db.Entry(_data).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); #region Xử lý line var lines = data.ResOrderItemViews.ToList(); var linez = data.ResOrderItemViewz.ToList(); DateTime _curDate = DateTime.Now; for (int i = 0; i < lines.Count; i++) { var itemz = linez[i]; var item = lines[i]; if (itemz != -1) { //có 2 tru?ng h?p: 1 - thêm m?i thu?ng DocumentOrderItemId==0, 2 - s?a d? li?u cu DocumentOrderItemId<>0 item.OrderId = _data.OrderId; if (item.OrderItemId == 0) { item.CreateDate = _curDate; this.InsertLine(item); } else { this.UpdateLine(item); } } else { //n?u xóa có 2 tru?ng h?p : 1 - xóa d? li?u có tru?c DocumentOrderItemId<>0, 2 - xóa d? li?u m?i thêm DocumentOrderItemId ==0 if (item.OrderId > 0) { this.DeleteLine(item.OrderItemId); } } } #endregion return(data.OrderId); } catch (Exception) { throw; } }
public int Insert(Models.ResOrderView data) { try { var tablewait = this.GetTable(data.TableId ?? 0); if (tablewait != null) { throw new Exception("Bàn này đã có người rồi!"); } //if (data.ResOrderItemViewz == null) throw new Exception("Phải nhập chi tiết!"); //var countline = data.ResOrderItemViewz.Where(m => m != -1).Count(); //if (countline == 0) throw new Exception("Phải nhập chi tiết!"); this.Validate(data); data.CreatedBy = GlobalVariant.GetAppUser().UserID; data.CreatedDateTime = DateTime.Now; data.ModifiedBy = GlobalVariant.GetAppUser().UserID; data.ModifiedDateTime = DateTime.Now; var _data = new Models.ResOrder(); this.MapView2Table(data, _data); this._db.ResOrders.Add(_data); this._db.SaveChanges(); if (data.ResOrderItemViewz == null) { return(_data.OrderId); } var countline = data.ResOrderItemViewz.Where(m => m != -1).Count(); if (countline == 0) { return(_data.OrderId); } var lines = data.ResOrderItemViews.ToList(); var linez = data.ResOrderItemViewz.ToList(); DateTime _curDate = DateTime.Now; for (int i = 0; i < lines.Count; i++) { var itemz = linez[i]; if (itemz != -1) { var item = lines[i]; item.OrderId = _data.OrderId; item.CreateDate = _curDate; this.InsertLine(item); } } return(_data.OrderId); } catch (Exception) { throw; } }