private int DeleteTblEmployeeBehalf(TblEmployeeBehalf row) { using (var context = new TimeAttEntities()) { var oldRow = (from e in context.TblEmployeeBehalves where e.Iserial == row.Iserial select e).SingleOrDefault(); if (oldRow != null) { context.DeleteObject(oldRow); } context.SaveChanges(); } return(row.Iserial); }
public void SaveMainRowExc() { if (SelectedMainRows != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRows, new ValidationContext(SelectedMainRows, null, null), valiationCollection, true); if (isvalid) { var save = SelectedMainRow.Iserial == 0; var saveRow = new TblEmployeeBehalf(); saveRow.InjectFrom(SelectedMainRow); if (save) { if (AllowAdd) { Loading = true; Client.UpdateOrInsertTblEmployeeBehalfAsync(saveRow, save, MainRowList.IndexOf(SelectedMainRow)); } else { MessageBox.Show(strings.AllowAddMsg); } } else { if (AllowUpdate) { Loading = true; Client.UpdateOrInsertTblEmployeeBehalfAsync(saveRow, save, MainRowList.IndexOf(SelectedMainRow)); } else { MessageBox.Show(strings.AllowUpdateMsg); } } } } }
private TblEmployeeBehalf UpdateOrInsertTblEmployeeBehalf(TblEmployeeBehalf newRow, bool save, int index, out int outindex) { outindex = index; using (var context = new TimeAttEntities()) { if (save) { context.TblEmployeeBehalves.AddObject(newRow); } else { var oldRow = (from e in context.TblEmployeeBehalves where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, context); } } context.SaveChanges(); return(newRow); } }