public GroupCreditWorthinesViewModel(GroupCreditWorthiness model) { if (model == null) { throw new ArgumentNullException("model"); } this.model = model; }
// Добавление группы public int AddGroupCreditWorthiness(GroupCreditWorthiness model) { using (DataContext cntx = new DataContext()) { try { cntx.Entry(model).State = EntityState.Added; cntx.SaveChanges(); // сохранение добавления } catch (Exception) { return(0); } } return(model.Id); }
// Редактирование группы public bool UpdateGroupCreditWorthiness(GroupCreditWorthiness model) { using (DataContext cntx = new DataContext()) { try { GroupCreditWorthiness oldModel = cntx.GroupCreditWorthinesss.FirstOrDefault(x => x.Id == model.Id); cntx.Entry(oldModel).CurrentValues.SetValues(model); // копируем изменения из model в oldModel cntx.SaveChanges(); } catch (Exception) { return(false); } } return(true); }
// удаление группы public bool DeleteGroupCreditWorthiness(GroupCreditWorthiness model) { using (DataContext cntx = new DataContext()) { try { GroupCreditWorthiness modelDel = cntx.GroupCreditWorthinesss.FirstOrDefault(x => x.Id == model.Id); cntx.Entry(modelDel).State = EntityState.Deleted; cntx.SaveChanges(); // сохранение удаления } catch (Exception) { return(false); } } return(true); }
private void AddModel() { GroupCreditWorthiness model = new GroupCreditWorthiness(); AddGroupCreditWorthinesView view = new AddGroupCreditWorthinesView(true, model, repository) { ShowInTaskbar = false }; view.ShowDialog(); if (view.DialogResult != true) { return; } model.Id = repository.AddGroupCreditWorthiness(model); if (model.Id == 0) { MessageBoxWPF.Show(StringProject.ErrorAddRecort, StringProject.ErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error); return; } AllModel.Add(new GroupCreditWorthinesViewModel(model)); }