Ejemplo n.º 1
0
        /// <summary>
        /// Update auto photos
        /// </summary>
        /// <param name="autoPhoto">Auto photo to update</param>
        public void UpdateAutoPhotos(AutoPhotos autoPhoto)
        {
            AutoRentEntities context     = new AutoRentEntities();
            DbTransaction    transaction = null;

            try
            {
                context.Connection.Open();
                transaction = context.Connection.BeginTransaction();

                context.AutoPhotos.Attach(context.AutoPhotos.Single(o => o.AutoNumber == autoPhoto.AutoNumber && o.DoDate == autoPhoto.DoDate));
                context.AutoPhotos.ApplyCurrentValues(autoPhoto);

                context.SaveChanges();
                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
            }
            finally
            {
                context.Connection.Close();
            }
        }
Ejemplo n.º 2
0
 public void InsertAutoPhotos(AutoPhotos autoPhotos)
 {
     if ((autoPhotos.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(autoPhotos, EntityState.Added);
     }
     else
     {
         this.ObjectContext.AutoPhotos.AddObject(autoPhotos);
     }
 }
Ejemplo n.º 3
0
 public void DeleteAutoPhotos(AutoPhotos autoPhotos)
 {
     if ((autoPhotos.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(autoPhotos, EntityState.Deleted);
     }
     else
     {
         this.ObjectContext.AutoPhotos.Attach(autoPhotos);
         this.ObjectContext.AutoPhotos.DeleteObject(autoPhotos);
     }
 }
        public void UpdateAutoPhotosTest()
        {
            AutoPhotosAccessor accessor   = new AutoPhotosAccessor();
            AutoPhotos         autoPhotos = new AutoPhotos
            {
                AutoNumber    = "AA 5676 CH",
                DoDate        = new DateTime(2011, 12, 28),
                PhotoFileName = "photo_5.jpg"
            };

            accessor.UpdateAutoPhotos(autoPhotos);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create new auto photo
        /// </summary>
        /// <param name="autoPhoto">Auto photo to add</param>
        public void CreateAutoPhotos(AutoPhotos autoPhoto)
        {
            AutoRentEntities context     = new AutoRentEntities();
            DbTransaction    transaction = null;

            try
            {
                context.Connection.Open();
                transaction = context.Connection.BeginTransaction();
                context.AddToAutoPhotos(autoPhoto);
                context.SaveChanges();
                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
            }
            finally
            {
                context.Connection.Close();
            }
        }
Ejemplo n.º 6
0
 public void UpdateAutoPhotos(AutoPhotos currentAutoPhotos)
 {
     this.ObjectContext.AutoPhotos.AttachAsModified(currentAutoPhotos, this.ChangeSet.GetOriginal(currentAutoPhotos));
 }