示例#1
0
        private void HandleRefreshApps(ProjectPartViewModel model, bool forceFromDB)
        {
            _currentModel = model;
            if (model != null)
            {
                if (model.Children != null && model.Children.Count > 0)
                {
                    //has children
                    CurrentApps.Clear();
                }
                else
                {
                    //get entity from cache
                    IEnumerable <App> dataQuery = null;

                    if (forceFromDB)
                    {
                        //clear cache
                        foreach (var item in CurrentApps)
                        {
                            DbContext.Detach(item);
                        }
                    }
                    else
                    {
                        var q1 = from i in DbContext.Entities
                                 where i.Entity is App
                                 select i.Entity;

                        var q2 = from i in q1.OfType <App>()
                                 where i.ProjectPartID == model.ProjectPartID
                                 select i;
                        if (q2.Count() != 0)
                        {
                            dataQuery = q2;
                            //CurrentApps.Clear();
                            //CurrentApps.Load(q2);
                        }
                    }

                    if (dataQuery == null)
                    {
                        dataQuery = from i in DbContext.Apps
                                    where i.ProjectPartID == model.ProjectPartID
                                    select i;
                    }


                    CurrentApps.Clear();
                    CurrentApps.Load(dataQuery);
                }
            }
        }
示例#2
0
        private void HandleQueryApp(string param)
        {
            //has children
            CurrentApps.Clear();

            string match = AppName.Trim().Replace("*", "%");

            //get entity from cache
            IEnumerable <App> dataQuery = DbContext.SearcyAppByName(match);

            CurrentApps.Load(dataQuery);
        }
示例#3
0
        private void HandleUpdate(App app)
        {
            try
            {
                DbContext.SaveChanges(SaveChangesOptions.Batch);
            }
            catch (Exception ex)
            {
                int index = CurrentApps.IndexOf(app);
                CurrentApps.RemoveAt(index);
                DbContext.Detach(app);

                var query = from i in DbContext.Apps
                            where i.AppName == app.AppName
                            select i;
                //DataServiceCollection<App> col = new DataServiceCollection<App>();
                //col.Load(query);
                CurrentApps.Insert(index, query.First());
                //App appIndb= DbContext.Apps.Single(item => item.AppName == app.AppName);
                //CurrentApps.Insert(index,appIndb);
                RaisePropertyChanged("CurrentApps");
                Messenger.Default.Send <Exception>(ex);
            }
        }