Пример #1
0
        private void DbConfigDilogCloseEventHanle(object Sender, DialogClosingEventArgs args)
        {
            if ((bool)args.Parameter == false)
            {
                return;
            }
            DataBaeConfigViewModel model = ((System.Windows.FrameworkElement)args.Session.Content).DataContext as DataBaeConfigViewModel;
            SynchronousDb          db    = AutoMapper.Mapper.Map <SynchronousDb>(model);

            switch (IsModify)
            {
            case true:
                dataBaseService.Update(db);
                break;

            case false:
                dataBaseService.Add(db);
                break;

            default:
                dataBaseService.Update(db);
                break;
            }

            LoadData();//重新加载数据
        }
Пример #2
0
        public async Task <bool> Update(SynchronousDb synchronousDb)
        {
            bool result = false;
            await repository.Update(synchronousDb, (item, err) => {
                if (err == null)
                {
                    result = true;
                }
            });

            return(result);
        }
Пример #3
0
        public async Task <bool> Add(SynchronousDb synchronousDb)
        {
            bool result = false;
            await repository.Add(synchronousDb, (item, error) =>
            {
                if (error != null)
                {
                    result = true;
                }
            });

            return(result);
        }
        Task <bool> IUpdateRepostry <SynchronousDb, int> .Add(SynchronousDb model, Action <SynchronousDb, Exception> callBack)
        {
            bool result = false;

            try
            {
                using (DataSyncContext context = new DataSyncContext())
                {
                    context.SynchronousDb.Add(model);
                    result = context.SaveChanges() > 0?true:false;
                }
                callBack(model, null);
            }
            catch (Exception ex)
            {
                callBack(model, ex);
            }
            return(Task.FromResult(result));
        }
        Task <bool> IUpdateRepostry <SynchronousDb, int> .Update(SynchronousDb model, Action <SynchronousDb, Exception> callBack)
        {
            bool result = false;

            try
            {
                using (DataSyncContext context = new DataSyncContext())
                {
                    //var obj=context.SynchronousDb.Where(c => c.ID == model.ID).FirstOrDefault();
                    //  obj = AutoMapper.Mapper.Map<SynchronousDb>(model);
                    context.Entry <SynchronousDb>(model).State = System.Data.Entity.EntityState.Modified;
                    result = context.SaveChanges() > 0?true:false;
                    callBack(model, null);
                }
            }
            catch (Exception ex)
            {
                callBack(model, ex);
            }
            return(Task.FromResult(result));
        }