Exemple #1
0
        public AjaxStoreResult SaveCustomersWithConfirmation()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                NorthwindDataContext     db               = this.DBContext;
                StoreDataHandler         dataHandler      = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <Customer> data             = dataHandler.ObjectData <Customer>();
                ConfirmationList         confirmationList = dataHandler.BuildConfirmationList("CustomerID");

                foreach (Customer customer in data.Deleted)
                {
                    db.Customers.Attach(customer);
                    db.Customers.DeleteOnSubmit(customer);
                }

                foreach (Customer customer in data.Updated)
                {
                    db.Customers.Attach(customer);
                    db.Refresh(RefreshMode.KeepCurrentValues, customer);
                }

                foreach (Customer customer in data.Created)
                {
                    //customer.TemporaryID = customer.CustomerID;
                    db.Customers.InsertOnSubmit(customer);
                }

                db.SubmitChanges();

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

                foreach (Customer customer in data.Deleted)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Updated)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Created)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }


                ajaxStoreResult.SaveResponse.ConfirmationList = confirmationList;
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success      = false;
                ajaxStoreResult.SaveResponse.ErrorMessage = e.Message;
            }

            return(ajaxStoreResult);
        }
Exemple #2
0
        public ActionResult ChucvuList_Save()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                QLVBEntities             db               = this.DBContext;
                StoreDataHandler         dataHandler      = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <DMCHUCVU> data             = dataHandler.ObjectData <DMCHUCVU>();
                ConfirmationList         confirmationList = dataHandler.BuildConfirmationList("MACHUCVU");

                foreach (DMCHUCVU c in data.Deleted)
                {
                    db.DMCHUCVUs.Attach(c);
                    db.DMCHUCVUs.DeleteObject(c);
                }

                foreach (DMCHUCVU c in data.Created)
                {
                    db.DMCHUCVUs.AddObject(c);
                }

                foreach (DMCHUCVU c in data.Updated)
                {
                    var orgRecord = db.DMCHUCVUs.Single(p => p.MACHUCVU == c.MACHUCVU);
                    db.DMCHUCVUs.ApplyCurrentValues(c);
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                int nCode = System.Runtime.InteropServices.Marshal.GetHRForException(e);

                if (nCode == -2146233087)
                {
                    ajaxStoreResult.SaveResponse.Message = "Trùng mã chức năng.";
                }
                else
                {
                    ajaxStoreResult.SaveResponse.Message = e.InnerException.Message;
                }
            }

            return(ajaxStoreResult);
        }
Exemple #3
0
        public void ProcessRequest(HttpContext context)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext     db               = new NorthwindDataContext();
                StoreDataHandler         dataHandler      = new StoreDataHandler(context);
                ChangeRecords <Supplier> data             = dataHandler.ObjectData <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)
                {
                    supplier.TemporaryID = supplier.SupplierID;
                    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.Msg     = e.Message;
            }

            sr.Write();
        }
Exemple #4
0
        public AjaxStoreResult SaveCustomersWithConfirmation()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                NorthwindDataContext db = this.DBContext;
                StoreDataHandler dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords<Customer> data = dataHandler.ObjectData<Customer>();
                ConfirmationList confirmationList = dataHandler.BuildConfirmationList("CustomerID");

                foreach (Customer customer in data.Deleted)
                {
                    db.Customers.Attach(customer);
                    db.Customers.DeleteOnSubmit(customer);
                }

                foreach (Customer customer in data.Updated)
                {
                    db.Customers.Attach(customer);
                    db.Refresh(RefreshMode.KeepCurrentValues, customer);
                }

                foreach (Customer customer in data.Created)
                {
                    db.Customers.InsertOnSubmit(customer);
                }

                db.SubmitChanges();

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

                foreach (Customer customer in data.Deleted)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Updated)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Created)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }


                ajaxStoreResult.SaveResponse.ConfirmationList = confirmationList;
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                ajaxStoreResult.SaveResponse.Message = e.Message;
            }

            return ajaxStoreResult;
        }
        public void ProcessRequest(HttpContext context)
        {
            Response sr = new Response(true);
            
            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(context);
                ChangeRecords<Supplier> data = dataHandler.ObjectData<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)
                {
                    supplier.TemporaryID = supplier.SupplierID;
                    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();
        }