private List <StoreVisaMachine> UpdateOrInsertVisaMachine(List <StoreVisaMachine> newRows, string company) { using (var context = new ccnewEntities(service.GetSqlConnectionString(company))) { try { foreach (var item in newRows) { var oldVisaMachinesRow = context.TblVisaMachines.FirstOrDefault(th => th.Iserial == item.VisaMachineIserial); var oldStoreVisaMachinesRow = context.TblStoreVisaMachines.FirstOrDefault(th => th.Iserial == item.StoreVisaMachineIserial); bool isVisaMachinesRow = oldVisaMachinesRow != null, isStoreVisaMachinesRow = oldStoreVisaMachinesRow != null; if (oldVisaMachinesRow == null) { oldVisaMachinesRow = new TblVisaMachine(); } oldVisaMachinesRow.Code = item.Code; oldVisaMachinesRow.TblBank = item.BankIserial; oldVisaMachinesRow.MachineId = item.MachineId; oldVisaMachinesRow.DiscountPercent = item.DiscountPercent; oldVisaMachinesRow.EntityAccount = item.EntityAccount; if (oldStoreVisaMachinesRow == null) { oldStoreVisaMachinesRow = new TblStoreVisaMachine() { TblVisaMachine1 = oldVisaMachinesRow } } ; oldStoreVisaMachinesRow.TblVisaMachine = item.VisaMachineIserial; oldStoreVisaMachinesRow.TblStore = item.StoreIserial; oldStoreVisaMachinesRow.IsDefault = item.IsDefault; if (!isVisaMachinesRow)// كده ده جديد هضيفه { context.TblVisaMachines.AddObject(oldVisaMachinesRow); } if (!isStoreVisaMachinesRow)// كده ده جديد هضيفه { oldVisaMachinesRow.TblStoreVisaMachines.Add(oldStoreVisaMachinesRow); context.TblStoreVisaMachines.AddObject(oldStoreVisaMachinesRow); } context.SaveChanges(); item.StoreVisaMachineIserial = oldStoreVisaMachinesRow.Iserial; item.VisaMachineIserial = oldVisaMachinesRow.Iserial; } } catch (Exception ex) { throw Helper.GetInnerException(ex); } return(newRows); } }
private int DeleteTblVisaMachine(TblVisaMachine row, int index, string company) { using (var entity = new ccnewEntities(GetSqlConnectionString(company))) { var query = (from e in entity.TblVisaMachines where e.Iserial == row.Iserial select e).SingleOrDefault(); if (query != null) { entity.DeleteObject(query); } entity.SaveChanges(); } return(row.Iserial); }
public void SaveMainRow() { if (SelectedMainRow != null) { var valiationCollection = new List <ValidationResult>(); var isvalid = Validator.TryValidateObject(SelectedMainRow, new ValidationContext(SelectedMainRow, null, null), valiationCollection, true); if (isvalid) { var save = SelectedMainRow.Iserial == 0; if (AllowUpdate != true && !save) { MessageBox.Show(strings.AllowUpdateMsg); return; } var saveRow = new TblVisaMachine(); saveRow.InjectFrom(SelectedMainRow); Glclient.UpdateOrInsertTblVisaMachineAsync(saveRow, save, MainRowList.IndexOf(SelectedMainRow), LoggedUserInfo.DatabasEname); } } }
private TblVisaMachine UpdateOrInsertTblVisaMachine(TblVisaMachine newRow, bool save, int index, out int outindex, string company) { outindex = index; using (var entity = new ccnewEntities(GetSqlConnectionString(company))) { if (save) { entity.TblVisaMachines.AddObject(newRow); } else { var oldRow = (from e in entity.TblVisaMachines where e.Iserial == newRow.Iserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, entity); } } entity.SaveChanges(); return(newRow); } }