Exemplo n.º 1
0
        public void SaveProductPhoto(int productId, string photoname, byte[] photo)
        {
            _context.BeginTransaction();

            var productPhoto = new ModelStore <ProductPhoto>()
                               .TrackChanges(ChangeTrackingStrategy.PropertyState);

            productPhoto.Add(new ProductPhoto()
            {
                ProductPhotoID     = productId,
                LargePhotoFileName = photoname,
                LargePhoto         = photo
            });

            var result = productPhoto.SaveChanges(_context);

            if (result.InsertedCount == 1)
            {
                var productPhotoID = productPhoto.FirstOrDefault().ProductPhotoID;

                var pordProdPhoto = new ModelStore <ProductProductPhoto>()
                                    .TrackChanges(ChangeTrackingStrategy.PropertyState);
                pordProdPhoto.Add(new ProductProductPhoto()
                {
                    ProductID      = productId,
                    ProductPhotoID = productPhotoID,
                    Primary        = 1
                });

                pordProdPhoto.SaveChanges(_context);
            }

            _context.Commit();
        }
Exemplo n.º 2
0
        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);
        }