コード例 #1
0
        public SettingsAaoViewModel(IBusiness _business, int _id)
        {
            try
            {
                business = _business;

                //Query lists for selection
                ConditionList   = new ObservableCollection <AaoCondition>(business.GetAllAaoConditionAsync().Result);
                CombinationList = new ObservableCollection <Aao>(business.GetAllAaoAsync().Result);
                VehicleList     = new ObservableCollection <Vehicle>(business.GetAllVehicleAsync().Result);

                //Query item with relations
                aao = business.GetAaoById(_id);
                if (aao == null)
                {
                    aao = new Aao();
                }

                //Do selection from list
                if (aao.Condition != null)
                {
                    SelectedCondition = ConditionList.Where(c => c.Id == aao.Condition.Id).SingleOrDefault();
                }

                if (aao.Combination != null)
                {
                    SelectedCombination = CombinationList.Where(c => c.Id == aao.Combination.Id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
            }
        }
コード例 #2
0
        public void DeleteAao(Aao _entity)
        {
            if (_entity == null || !_entity.IsValid)
            {
                new ArgumentNullException("Aao");
            }

            using (var _databaseContext = new DatabaseContext())
            {
                _entity = GetAaoById(_entity.Id);
                _entity.Vehicles.ToList().ForEach(v => _databaseContext.AaoVehicles.Remove(v));
                _databaseContext.Aaos.Remove(_entity);

                _databaseContext.SaveChanges();
            }
        }
コード例 #3
0
        public int AddOrUpdateAao(Aao _entity)
        {
            if (_entity == null || !_entity.IsValid)
            {
                new ArgumentNullException("Aao");
            }

            using (var _databaseContext = new DatabaseContext())
            {
                _entity = _databaseContext.UpdateGraph(_entity,
                                                       map => map.AssociatedEntity(a => a.Combination).AssociatedEntity(a => a.Condition)
                                                       .OwnedCollection(a => a.Vehicles, with => with.AssociatedEntity(v => v.Vehicle)));

                _databaseContext.SaveChanges();
                return(_entity.Id);
            }
        }