public MappingViewModel AddMapping(Mapping mapping) { var mappingViewModel = new MappingViewModel(this, mapping); MappingsList.Add(mappingViewModel); return(mappingViewModel); }
public TModel Get <TEntity, TModel>(Expression <Func <TEntity, bool> > filterExpression = null) where TEntity : class { if (MappingsList.Exist <TEntity, TModel>()) { var query = _repository.GetList(filterExpression); return(query.AsQuery <TEntity, TModel>().FirstOrDefault()); } var entity = _repository.Get(filterExpression); return(entity.To <TModel>()); }
public TModel Get <TEntity, TModel>(int id) where TEntity : class, IEntity { if (MappingsList.Exist <TEntity, TModel>()) { var query = _repository.GetQueryById <TEntity>(id); return(query.AsQuery <TEntity, TModel>().FirstOrDefault()); } var entity = _repository.Get <TEntity>(id); return(entity.To <TModel>()); }
public static List <TModel> To <TEntity, TModel>(this IQueryable <TEntity> input) where TEntity : class { if (typeof(TEntity) == typeof(TModel)) { return(input.ToList().Cast <TModel>().ToList()); } if (MappingsList.Exist <TEntity, TModel>()) { return(input.AsQuery <TEntity, TModel>().ToList()); } return(input.ToList().To <TModel>()); }
public void RemoveMapping(MappingViewModel mappingViewModel) { if (mappingViewModel.Mapping.DeviceBindings.Count > 0) { var result = MessageBox.Show("Are you sure you want to remove '" + mappingViewModel.Mapping.Title + "'?", "Remove mapping?", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result != MessageBoxResult.Yes) { return; } } if (Profile.RemoveMapping(mappingViewModel.Mapping)) { MappingsList.Remove(mappingViewModel); } }
public async void RemoveMapping(MappingViewModel mappingViewModel) { if (mappingViewModel.Mapping.DeviceBindings.Count > 0) { var dialog = new BoolDialog("Remove mapping", "Are you sure you want to remove the mapping: " + mappingViewModel.Mapping.Title + "?"); var result = (bool?)await DialogHost.Show(dialog, ProfileDialogIdentifier); if (result == null || !result.Value) { return; } } if (Profile.RemoveMapping(mappingViewModel.Mapping)) { MappingsList.Remove(mappingViewModel); } }