Пример #1
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            ChangeRecords<TestPerson> persons = handler.BatchObjectData<TestPerson>();
            var store = this.GetCmp<Store>("Store1");

            foreach (TestPerson created in persons.Created)
            {
                TestPerson.AddPerson(created);

                var record = store.GetByInternalId(created.PhantomId);
                record.CreateVariable = true;
                record.SetId(created.Id);
                record.Commit();
                created.PhantomId = null;
            }

            foreach (TestPerson deleted in persons.Deleted)
            {
                TestPerson.DeletePerson(deleted.Id.Value);
                store.CommitRemoving(deleted.Id.Value);
            }

            foreach (TestPerson updated in persons.Updated)
            {
                TestPerson.UpdatePerson(updated);

                var record = store.GetById(updated.Id.Value);
                record.Commit();
            }

            return this.Direct();
        }
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            ChangeRecords <TestPerson> persons = handler.BatchObjectData <TestPerson>();
            var store = this.GetCmp <Store>("Store1");

            foreach (TestPerson created in persons.Created)
            {
                TestPerson.AddPerson(created);

                var record = store.GetByInternalId(created.PhantomId);
                record.CreateVariable = true;
                record.SetId(created.Id);
                record.Commit();
                created.PhantomId = null;
            }

            foreach (TestPerson deleted in persons.Deleted)
            {
                TestPerson.DeletePerson(deleted.Id.Value);
                store.CommitRemoving(deleted.Id.Value);
            }

            foreach (TestPerson updated in persons.Updated)
            {
                TestPerson.UpdatePerson(updated);

                var record = store.GetById(updated.Id.Value);
                record.Commit();
            }

            return(this.Direct());
        }
Пример #3
0
        public DirectResult SaveData(string id, FormCollection values, string startDate, string endDate)
        {
            DirectResult response = new DirectResult();

            Ext.Net.Store            store       = X.GetCmp <Ext.Net.Store>("StoreTest");
            StoreDataHandler         dataHandler = new StoreDataHandler(values["data"]);
            ChangeRecords <TestData> data        = dataHandler.BatchObjectData <TestData>();

            for (int i = 0; i < data.Updated.Count; i++)
            {
                TestData testData = data.Updated[i];

                //we want to remove the record since it is processed so we use the delete record option
                ModelProxy record = store.GetById(testData.id);
                store.Remove(record);
                store.CommitRemoving(testData.id);
            }

            return(response);
        }
        public void ProcessRequest(HttpContext context)
        {
            Response sr = new Response(true);
            
            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(context);
                ChangeRecords<Supplier> data = dataHandler.BatchObjectData<Supplier>();
                //ConfirmationList confirmationList = dataHandler.BuildConfirmationList("SupplierID");

                foreach (Supplier supplier in data.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Created)
                {
                    db.Suppliers.InsertOnSubmit(supplier);
                }

                db.SubmitChanges();

                //ideally we should confirm after each operation
                //but LINQ make batch submit of changes

                foreach (Supplier supplier in data.Deleted)
                {
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Updated)
                {
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Created)
                {
                    //confirmationList[supplier.TemporaryID.ToString()].ConfirmRecord(supplier.SupplierID.ToString());
                }

                
                StoreResponseData response = new StoreResponseData();
                //response.Confirmation = confirmationList;

                sr.Data = response.ToString();
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            sr.Write();
        }
        public void ProcessRequest(HttpContext context)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext     db          = new NorthwindDataContext();
                StoreDataHandler         dataHandler = new StoreDataHandler(context);
                ChangeRecords <Supplier> data        = dataHandler.BatchObjectData <Supplier>();
                //ConfirmationList confirmationList = dataHandler.BuildConfirmationList("SupplierID");

                foreach (Supplier supplier in data.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Created)
                {
                    db.Suppliers.InsertOnSubmit(supplier);
                }

                db.SubmitChanges();

                //ideally we should confirm after each operation
                //but LINQ make batch submit of changes

                foreach (Supplier supplier in data.Deleted)
                {
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Updated)
                {
                    //confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Created)
                {
                    //confirmationList[supplier.TemporaryID.ToString()].ConfirmRecord(supplier.SupplierID.ToString());
                }


                StoreResponseData response = new StoreResponseData();
                //response.Confirmation = confirmationList;

                sr.Data = response.ToString();
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            sr.Write();
        }
        private ChangeRecords <TModel> GetChangedRecords(DirectEventArgs e)
        {
            StoreDataHandler dataHandler = new StoreDataHandler(e.ExtraParams["changedData"]);

            return(dataHandler.BatchObjectData <TModel>());
        }