public void ProcessRequest(HttpContext context)
        {
            string action = context.Request["action"];

            if (string.IsNullOrEmpty(action) || Store.Action(action) == StoreAction.Read)
            {
                this.ReturnData(context);
                return;
            }

            StoreResponseData sr = new StoreResponseData();

            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(context);
                List<Supplier> dataList = dataHandler.ObjectData<Supplier>();
                StoreAction storeAction = Store.Action(action);

                foreach (Supplier supplier in dataList)
                {
                    if (storeAction == StoreAction.Destroy)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Suppliers.DeleteOnSubmit(supplier);
                    }
                    else if (storeAction == StoreAction.Update)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    }
                    else if (storeAction == StoreAction.Create)
                    {
                        db.Suppliers.InsertOnSubmit(supplier);
                    }
                }

                db.SubmitChanges();

                if (storeAction != StoreAction.Destroy)
                {
                    sr.Data = JSON.Serialize(dataList);
                    sr.Return();
                    return;
                }
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            sr.Return();
        }
        public object SaveSuppliers(string data, string action)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(data);
                List<Supplier> dataList = dataHandler.ObjectData<Supplier>();
                StoreAction storeAction = Store.Action(action);

                foreach (Supplier supplier in dataList)
                {
                    if (storeAction == StoreAction.Destroy)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Suppliers.DeleteOnSubmit(supplier);
                    }
                    else if (storeAction == StoreAction.Update)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    }
                    else if (storeAction == StoreAction.Create)
                    {
                        db.Suppliers.InsertOnSubmit(supplier); 
                    }
                }

                db.SubmitChanges();

                if (storeAction != StoreAction.Destroy)
                {
                    return dataList.ToList<Supplier, SerializableEntity<Supplier>>();
                }
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            return sr;
        }
Exemplo n.º 3
0
        public XResponse SaveSuppliers(string data)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(data);
                ChangeRecords<Supplier> dataList = dataHandler.ObjectData<Supplier>();

                foreach (Supplier supplier in dataList.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                }

                foreach (Supplier supplier in dataList.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                }

                foreach (Supplier supplier in dataList.Created)
                {
                    supplier.TemporaryID = supplier.SupplierID;
                    db.Suppliers.InsertOnSubmit(supplier);
                }

                db.SubmitChanges();
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            return sr;
        }
Exemplo n.º 4
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>();

                foreach (Supplier supplier in data.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                }
                
                foreach (Supplier supplier in data.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                }

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

                db.SubmitChanges();
            }
            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();
        }