private void SaveOrUpdateExcel(ExcelImportRule behavior) { var context = _holder.Context; var entity = context.ExcelImportRule.FirstOrDefault(e => e.Identificator == behavior.Identificator) ?? new ExcelImportRulePoco(); entity.Bridge.FromModel(behavior); if (entity.IsNew) { entity.AddOrAttach(context); } context.SaveChanges(); }
private static void FillViewModel(ExcelRuleViewModel viewModel, ExcelImportRule model) { viewModel._model = model; viewModel.Identificator = model.Identificator; viewModel.Name = model.Name; viewModel.Description = model.Description; viewModel.RowOffset = model.RowOffset; viewModel.ColumnOffset = model.ColumnOffset; viewModel.UseCsvFile = model.CsvMode; viewModel.WorksheetIndex = model.WorksheetIndex; FillFieldViewModel(viewModel.NameField, model.Columns.FirstOrDefault(c => c.Name == viewModel.NameField.Name)); FillFieldViewModel(viewModel.BrandField, model.Columns.FirstOrDefault(c => c.Name == viewModel.BrandField.Name)); FillFieldViewModel(viewModel.PartNumberField, model.Columns.FirstOrDefault(c => c.Name == viewModel.PartNumberField.Name)); FillFieldViewModel(viewModel.PriceField, model.Columns.FirstOrDefault(c => c.Name == viewModel.PriceField.Name)); FillFieldViewModel(viewModel.BalanceField, model.Columns.FirstOrDefault(c => c.Name == viewModel.BalanceField.Name)); FillFieldViewModel(viewModel.AnalogsField, model.Columns.FirstOrDefault(c => c.Name == viewModel.AnalogsField.Name)); /* * FillFieldViewModel(viewModel.DistributorField, model.Columns.FirstOrDefault(c => c.Name == viewModel.DistributorField.Name)); * FillFieldViewModel(viewModel.CommentaryField, model.Columns.FirstOrDefault(c => c.Name == viewModel.CommentaryField.Name)); */ viewModel.RaisePropertyChanged("Model"); viewModel.RaisePropertyChanged("IsNew"); }