Beispiel #1
0
 //delete one item from database, actually set isDelete = true
 private void deleteBtn_Click(object sender, EventArgs e)
 {
     if (tabControl.SelectedTab == tabControl.TabPages[0])
     {
         {
             DialogResult result = MessageBox.Show(this, "Are you going to delete this item from database?", "Please confirm", MessageBoxButtons.YesNo);
             if (result == DialogResult.Yes)
             {
                 ICriterion[] expressions = new ICriterion[2];
                 expressions[0] = Expression.Eq("asset", itemsDataGridView.Rows[rowindex].Cells["Asset"].Value);
                 expressions[1] = Expression.Eq("isDelete", false);
                 IList <Item> items = repo.Query <Item>(expressions);
                 if (items.Count > 1)
                 {
                     MessageBox.Show("There exist at least two items with the same asset,please check it");
                 }
                 else
                 {
                     items[0].isDelete = true;
                     repo.Update(items[0]);
                     showAllItems(repo);
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("You don't have right to delete staff!");
     }
 }
Beispiel #2
0
        public void save_update_delete()
        {
            var playlist = new Playlist {
                Name = "New Playlist"
            };

            _playlistRepo.Save(playlist);
            Assert.IsTrue(playlist.PlaylistId > 0);

            var playlistId = playlist.PlaylistId;

            playlist = _playlistRepo.Get(playlistId);
            Assert.IsNotNull(playlist);
            Assert.AreEqual(playlistId, playlist.PlaylistId);

            playlist.Name = "Updated Playlist";
            _playlistRepo.Update(playlist);

            playlist = _playlistRepo.Get(playlistId);
            Assert.IsNotNull(playlist);
            Assert.AreEqual("Updated Playlist", playlist.Name);

            _playlistRepo.Delete(playlist);
            playlist = _playlistRepo.Get(playlistId);
            Assert.IsNull(playlist);
        }
Beispiel #3
0
 public IEnumerable <string> Update <T>(T entity) where T : class
 {
     using (NHibernateRepository <T> repository = new NHibernateRepository <T>(ConnectionString, DomainAssemblyName))
     {
         IEnumerable <string> rules;
         repository.Update(entity, out rules);
         return(rules);
     }
 }
Beispiel #4
0
        public void Update()
        {
            NHibernateRepository repo = new NHibernateRepository();
            IList <Staff>        st   = repo.Query <Staff>();

            st[0].groupCode = "1345655";
            repo.Update(st[0]);
            int id = st[0].staffID;


            Assert.AreEqual("13456", repo.Query <Staff>()[0].groupCode);
        }
Beispiel #5
0
 /// <summary>
 /// Método para actualizar un usuario.
 /// </summary>
 /// <param name="usuario"></param>
 public void ActualizarUsuario(Usuario usuario)
 {
     try
     {
         IRepository <Usuario> uRepo = new NHibernateRepository <Usuario>();
         uRepo.Update(usuario);
     }
     catch (Exception e)
     {
         log.Error(e.Message, e);
         throw new DataAccessException(DataAccessException.EXCEPTION, e);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Método para actualizar un proveedor.
 /// </summary>
 /// <param name="proveedor"></param>
 public void ActualizarProveedor(Proveedor proveedor)
 {
     try
     {
         IRepository <Proveedor> pRepo = new NHibernateRepository <Proveedor>();
         pRepo.Update(proveedor);
     }
     catch (Exception e)
     {
         log.Error(e.Message, e);
         throw new DataAccessException(DataAccessException.EXCEPTION, e);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Método para eliminar un usuario.
        /// </summary>
        /// <param name="id"></param>
        public void EliminarUsuario(int id)
        {
            Usuario usuario;

            try
            {
                IRepository <Usuario> uRepo = new NHibernateRepository <Usuario>();
                usuario = uRepo.Get(id);

                usuario.Estatus = false;

                uRepo.Update(usuario);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                throw new DataAccessException(DataAccessException.EXCEPTION, e);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Método para eliminar un proveedor.
        /// </summary>
        /// <param name="id"></param>
        public void EliminarProveedor(int id)
        {
            Proveedor proveedor;

            try
            {
                IRepository <Proveedor> pRepo = new NHibernateRepository <Proveedor>();
                proveedor = pRepo.Get(id);

                proveedor.Estatus = false;

                pRepo.Update(proveedor);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                throw new DataAccessException(DataAccessException.EXCEPTION, e);
            }
        }
        public void Update(IndividualEntity entity)
        {
            // Guard against invalid arguments.
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            if (entity.Id <= 0)
            {
                throw new InvalidOperationException("Entity is invalid, the Id must be greater than 0.");
            }

            try
            {
                repository.Update(entity);
            }
            catch (Exception exception)
            {
                // Throw an exception if the Id was not returned.
                throw new InvalidOperationException("Failed to update.", exception);
            }
        }
Beispiel #10
0
        public void Saving_a_state_machine_should_work()
        {
            Guid transactionId;

            using (var unitOfWork = UnitOfWork.Start())
                using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
                {
                    using (var repository = new NHibernateRepository())
                    {
                        ExampleStateMachine machine = new ExampleStateMachine();

                        repository.Save(machine);

                        transactionId = machine.TransactionId;
                    }

                    transaction.Commit();
                }
            UnitOfWork.Finish();

            using (var unitOfWork = UnitOfWork.Start())
                using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
                {
                    using (var repository = new NHibernateRepository())
                    {
                        ExampleStateMachine machine = repository.Get <ExampleStateMachine>(transactionId);

                        machine.SubmitOrder();

                        repository.Update(machine);
                    }

                    transaction.Commit();
                }
            UnitOfWork.Finish();
        }
        public void Saving_a_state_machine_should_work()
        {
            Guid transactionId;

            using (var unitOfWork = UnitOfWork.Start())
            using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
            {
                using(var repository = new NHibernateRepository() )
                {
                    ExampleStateMachine machine = new ExampleStateMachine();

                    repository.Save(machine);

                    transactionId = machine.TransactionId;
                }

                transaction.Commit();
            }
            UnitOfWork.Finish();

            using (var unitOfWork = UnitOfWork.Start())
            using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
            {
                using (var repository = new NHibernateRepository())
                {
                    ExampleStateMachine machine = repository.Get<ExampleStateMachine>(transactionId);

                    machine.SubmitOrder();

                    repository.Update(machine);
                }

                transaction.Commit();
            }
            UnitOfWork.Finish();
        }
            public void UpdatesAnElement()
            {
                //// SETUP

                var testEntity = new TestEntity { Name = "Name" };
                const string UpdatedName = "New Name";

                using (var session = GetInMemoryDatabaseSession())
                {
                    // Add the test entity.
                    using (var transaction = session.BeginTransaction())
                    {
                        session.Save(testEntity);
                        transaction.Commit();
                    }

                    // Change the entity name.
                    testEntity.Name = UpdatedName;

                    // Mock session factory that will provide the in-memory session.
                    var mockSessionFactory = new Mock<ISessionFactory>();
                    mockSessionFactory.Setup(mock => mock.OpenSession()).Returns(session);

                    // Setup target
                    var target = new NHibernateRepository<TestEntity>(mockSessionFactory.Object);

                    // EXECUTE
                    var result = target.Update(testEntity);

                    // VERIFY
                    session.Evict(testEntity);
                    var updatedEntity = session.Get<TestEntity>(testEntity.Id);
                    Assert.True(result);
                    Assert.AreEqual(UpdatedName, updatedEntity.Name);
                }
            }
            public void ReturnsFalseOnFailure()
            {
                //// SETUP

                const string OriginalName = "Name";
                const string UpdatedName = "New Name";
                var testEntity = new TestEntity { Name = OriginalName };

                using (var session = GetInMemoryDatabaseSession())
                {
                    // Add the test entity.
                    using (var transaction = session.BeginTransaction())
                    {
                        session.Save(testEntity);
                        transaction.Commit();
                    }

                    // Change the entity name and ID (to an invalid ID).
                    var validId = testEntity.Id;
                    testEntity.Id++;
                    testEntity.Name = UpdatedName;

                    // Mock session factory that will provide the in-memory session.
                    var mockSessionFactory = new Mock<ISessionFactory>();
                    mockSessionFactory.Setup(mock => mock.OpenSession()).Returns(session);

                    // Setup target
                    var target = new NHibernateRepository<TestEntity>(mockSessionFactory.Object);

                    // EXECUTE
                    var result = target.Update(testEntity);

                    // VERIFY
                    session.Evict(testEntity);
                    var updatedEntity = session.Get<TestEntity>(validId);
                    Assert.False(result);
                    Assert.AreEqual(OriginalName, updatedEntity.Name);
                }
            }