public static IEnumerable <ClientCodeRealtion> ConvertGridDataDbEnumerableObject(this DataGrid clientCodeDataGrid, int clientId) { var selectedList = new List <ClientCodeRealtion>(); var cac = ClientsAppContext.GetContextInstance(); ItemCollection items = clientCodeDataGrid.Items; for (int i = 0; i < items.Count; i++) { var it = items[i]; ClientCodeRealtion temp = it as ClientCodeRealtion; if (temp == null) { break; } if (temp.ClientID == null) { temp.ClientID = clientId; } var code = cac.GetAllCodes().Single(a => string.Equals(temp.Description, a.Description)); temp.CodeID = code.ID; var mycheckbox = clientCodeDataGrid.Columns[4].GetCellContent(it) as CheckBox; if (mycheckbox.IsChecked.Value) { temp.ToDelete = true; } selectedList.Add(temp); } cac.RemoveAllClientCodes(clientId); foreach (var ccrs in selectedList) { if (!ccrs.ToDelete) { var temmpClientCode = new ClientCode() { client_ID = ccrs.ClientID, code_ID = ccrs.CodeID, CreatedTime = ccrs.AddedClientCodeRelationDate, }; cac.AddClientCode(temmpClientCode); } } selectedList.RemoveAll(a => a.ToDelete); return(selectedList); }
public static void Insert(this ClientCodeRealtion cc) { ClientsAppContext cac = ClientsAppContext.GetContextInstance(); Code code = cac.GetAllCodes().Single(a => string.Equals(cc.Description, a.Description)); ClientCode clientcode = new ClientCode() { client_ID = cc.ClientID, code_ID = code.ID, Description = cc.Description, CreatedTime = DateTime.Now, }; cac.AddClientCode(clientcode); }
public void Insert <T>(T ob, string displayValue) { var cc = ob as ClientCodeRealtion; if (insertMode) { var InsertRecord = MessageBox.Show("Do you want to add " + displayValue + " ?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question); if (InsertRecord == MessageBoxResult.Yes) { cc.Insert(); MessageBox.Show(displayValue + " has being added!", "Inserting Record", MessageBoxButton.OK, MessageBoxImage.Information); } insertMode = false; } else { ClientsAppContext.GetContextInstance().SaveChanges(); } }