private TblRequestForSampleEvent UpdateOrInsertTblRequestForSampleEvent(TblRequestForSampleEvent newRow, bool save, int index, out int outindex) { outindex = index; using (var context = new WorkFlowManagerDBEntities()) { //var requestForSample = context.TblRequestForSamples.FirstOrDefault(x => x.Iserial == newRow.TblSalesOrder); //if (requestForSample != null) // requestForSample.TblRequestForSampleStatus = newRow.TblRequestForSampleStatus; if (save) { context.TblRequestForSampleEvents.AddObject(newRow); } else { var oldRow = (from e in context.TblRequestForSampleEvents where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, context); } } context.SaveChanges(); return(newRow); } }
private int DeleteTblRequestForSampleEvent(TblRequestForSampleEvent row) { using (var context = new WorkFlowManagerDBEntities()) { var oldRow = (from e in context.TblRequestForSampleEvents where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldRow != null) { context.DeleteObject(oldRow); } context.SaveChanges(); } return(row.Iserial); }
private TblRequestForSample UpdateOrInsertTblRequestForSample(TblRequestForSample newRow, int UserIserial, bool save, int index, out int outindex) { outindex = index; using (var context = new WorkFlowManagerDBEntities()) { if (save) { var serial = GetMaxSample(newRow.TblStyle, newRow.TblSupplier); newRow.Code = newRow.Code + "-" + serial; newRow.SerialNo = serial; newRow.TblRequestForSampleStatus = context.TblRequestForSampleStatus.FirstOrDefault(x => x.Code == "N/A").Iserial; context.TblRequestForSamples.AddObject(newRow); context.SaveChanges(); var newevent = new TblRequestForSampleEvent { ApprovedBy = UserIserial, RequestDate = newRow.CreationDate, DeliveryDate = newRow.EstimatedDeliveryDate, TblRequestForSampleStatus = newRow.TblRequestForSampleStatus, TblSalesOrder = newRow.Iserial }; context.TblRequestForSampleEvents.AddObject(newevent); } else { var oldRow = (from e in context.TblRequestForSamples where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { if (oldRow.TblSupplier != newRow.TblSupplier) { var serial = GetMaxSample(newRow.TblStyle, newRow.TblSupplier); newRow.Code = newRow.Code + "-" + serial; newRow.SerialNo = serial; } GenericUpdate(oldRow, newRow, context); } } context.SaveChanges(); return(newRow); } }