Exemple #1
0
        public string Update <TModel>(bool autoCommit,
                                      IModelStore <TModel> modelList)
            where TModel : class, new()
        {
            if (autoCommit)
            {
                _context.BeginTransaction();
                modelList.SaveChanges(_context);
                _context.Commit();
            }
            else
            {
                modelList.SaveChanges(_context);
            }

            return("Success");
        }
        public int SavePerson(IModelStore <Person> person,
                              IModelStore <BusinessEntityAddress> addresses,
                              IModelStore <PersonPhone> phones,
                              IModelStore <Customer> customers)
        {
            int intPersonId = 0;

            _context.BeginTransaction();

            if (person.TrackedCount(StateTrackable.NewModified) == 1)
            {
                var businessEntity = new ModelStore <BusinessEntity>()
                                     .TrackChanges(ChangeTrackingStrategy.PropertyState);

                businessEntity.Add(new BusinessEntity()
                {
                    ModifiedDate = DateTime.Now
                });

                var result = businessEntity.SaveChanges(_context);

                if (result.InsertedCount == 1)
                {
                    intPersonId = businessEntity.FirstOrDefault().BusinessEntityID;
                    person.SetValue(0, "Businessentityid", intPersonId);
                }
            }
            else
            {
                intPersonId = person.FirstOrDefault().Businessentityid;
            }


            SetPrimaryKey(person, addresses, phones, customers);

            //Save person address, phone, customer
            person.SaveChanges(_context);
            addresses.SaveChanges(_context);
            phones.SaveChanges(_context);
            customers.SaveChanges(_context);

            _context.Commit();

            return(intPersonId);
        }
        public int SaveProductAndPrice(IModelStore <Product> product,
                                       IModelStore <HistoryPrice> prices)
        {
            int intProductId = 0;

            _context.BeginTransaction();

            product.SaveChanges(_context);

            intProductId = product.FirstOrDefault().Productid;

            SetPricePrimaryKey(product, prices);
            prices.SaveChanges(_context);

            _context.Commit();

            return(intProductId);
        }
        public int SaveSalesOrderAndDetail(IModelStore <SalesOrderHeader> salesOrderHeaders,
                                           IModelStore <SalesOrderDetail> salesOrderDetails)
        {
            int intSalesOrderId = 0;

            _context.BeginTransaction();

            salesOrderHeaders.SaveChanges(_context);

            intSalesOrderId = salesOrderHeaders.FirstOrDefault().SalesOrderID;

            SetPrimaryKey(salesOrderHeaders, salesOrderDetails);
            salesOrderDetails.SaveChanges(_context);

            _context.Commit();

            return(intSalesOrderId);
        }
        public int SaveHistoryPrices(IModelStore <SubCategory> subcate,
                                     IModelStore <Product> product,
                                     IModelStore <HistoryPrice> prices)
        {
            int intSubCateId = 0;
            int intProductId = 0;

            _context.BeginTransaction();

            subcate.SaveChanges(_context);

            intSubCateId = subcate.FirstOrDefault().Productsubcategoryid;

            SetProductPrimaryKey(subcate, product);
            product.SaveChanges(_context);
            intProductId = product.FirstOrDefault().Productid;

            SetPricePrimaryKey(product, prices);
            prices.SaveChanges(_context);

            _context.Commit();

            return(intSubCateId);
        }