private TblContractDetail DeleteContractDetail(TblContractDetail row, int userIserial) { using (var scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(600))) { using (var context = new WorkFlowManagerDBEntities()) { var oldRow = (from e in context.TblContractDetails where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldRow != null) { var headerId = oldRow.TblContractHeader; context.TblContractDetailDels.AddObject(new TblContractDetailDel() { TblLkpBrandSection = oldRow.TblLkpBrandSection, AccCost = oldRow.AccCost, Cost = oldRow.Cost, CreatedBy = userIserial, CreationDate = DateTime.Now, DeliveryDate = oldRow.DeliveryDate, FabricCost = oldRow.FabricCost, Material = oldRow.Material, OperationCost = oldRow.OperationCost, Qty = oldRow.Qty, TblColor = oldRow.TblColor, TblContractHeader = oldRow.TblContractHeader, TblSalesOrderColor = oldRow.TblSalesOrderColor, LastChangeDate = oldRow.LastChangeDate, LastChangeUser = oldRow.LastChangeUser, }); context.DeleteObject(oldRow); var header = context.TblContractHeaders.FirstOrDefault(h => h.Iserial == headerId); header.Amount = header.TblContractDetails.Sum(r => r.Total); } context.SaveChanges(); } scope.Complete(); } return(row); }
//[OperationContract] private TblContractDetail UpdateOrInsertContractDetail( TblContractDetail newRow, int userIserial, int index, out int outindex) { throw new Exception("Save Contracts On Stitch"); outindex = index; newRow.TblContractHeader1 = null; newRow.TblSalesOrderColor1 = null; newRow.TblColor1 = null; using (var context = new WorkFlowManagerDBEntities()) { var oldRow = (from e in context.TblContractDetails where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { //context.Entry(oldRow).CurrentValues.SetValues(newRow); var result = SharedOperation.GenericUpdate(oldRow, newRow, context); if (result.Count() > 0) { newRow.LastChangeUser = userIserial; newRow.LastChangeDate = DateTime.Now; } } else { newRow.CreatedBy = userIserial; newRow.LastChangeUser = userIserial; newRow.CreationDate = DateTime.Now; newRow.LastChangeDate = DateTime.Now; context.TblContractDetails.AddObject(newRow); } context.SaveChanges(); return(newRow); } }