예제 #1
0
        public IActionResult Delete(int id, [FromServices] CustomerDb db)
        {
            int rowsAffected = _dao.Delete(id, db);

            if (rowsAffected <= 0)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = "error occurred while deleting customer" }));
            }
            return(Ok());
        }
예제 #2
0
        public void CustomerDaoTests()
        {
            Assert.AreEqual(91, customerDao.GetAll().Count);

            Customer c = new Customer(new DefaultCustomerClassificationCalculator());

            c.Id          = "MPOLL";
            c.CompanyName = "Interface21";
            customerDao.Save(c);
            c = customerDao.Get("MPOLL");
            Assert.AreEqual(c.Id, "MPOLL");
            Assert.AreEqual(c.CompanyName, "Interface21");

            //Without flushing, nothing changes in the database:
            int customerCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Customers");

            Assert.AreEqual(91, customerCount);

            //Flush the session to execute sql in the db.
            SessionFactoryUtils.GetSession(sessionFactory, true).Flush();

            //Now changes are visible outside the session but within the same database transaction
            customerCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Customers");
            Assert.AreEqual(92, customerCount);

            Assert.AreEqual(92, customerDao.GetAll().Count);

            c.CompanyName = "SpringSource";

            customerDao.Update(c);

            c = customerDao.Get("MPOLL");
            Assert.AreEqual(c.Id, "MPOLL");
            Assert.AreEqual(c.CompanyName, "SpringSource");

            customerDao.Delete(c);


            SessionFactoryUtils.GetSession(sessionFactory, true).Flush();
            customerCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Customers");
            Assert.AreEqual(92, customerCount);

            try
            {
                c = customerDao.Get("MPOLL");
                Assert.Fail("Should have thrown HibernateObjectRetrievalFailureException when finding customer with Id = MPOLL");
            }
            catch (HibernateObjectRetrievalFailureException e)
            {
                Assert.AreEqual("Customer", e.PersistentClassName);
            }
        }
예제 #3
0
 public void Delete(int id)
 {
     customerDao.Delete(id);
 }
예제 #4
0
 public void Delete(Customer customer)
 {
     _customerDao.Delete(customer);
 }
예제 #5
0
 public IResult Delete(Customer customer)
 {
     _customerDao.Delete(customer);
     return(new SuccessResult(Messages.DeletedCustomer));
 }
 public void Delete(long id)
 {
     CustomerDao.Delete(id);
 }
 public void Delete(Customer entity)
 {
     _customerDao.Delete(entity);
 }