Пример #1
0
        public void SaveReservation(Roomregister roomRegister, Roomregisterdetail roomRegisterDetail,
                                    IList <Roomhistory> roomHistories, Customer customer)
        {
            ITransaction transaction = null;

            try
            {
                using (transaction = _session.BeginTransaction())
                {
                    _customerDao.Save(customer);
                    roomRegister.Customer = customer;
                    _roomRegisterDao.Save(roomRegister);
                    foreach (var roomhistory in roomHistories)
                    {
                        roomhistory.Roomregister = roomRegister;

                        _roomHistoryDao.Save(roomhistory);
                    }
                    transaction.Commit();
                }
            }
            catch (Exception)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw;
            }
        }
        public CustomerResult Create(CustomerParam param)
        {
            Data.Entity.Customer entity = CustomerParamConverter.Convert(param, null);
            CustomerDao.Save(entity);

            return(CustomerResultConverter.Convert(entity));
        }
Пример #3
0
    protected void btnAdd_OnClick(object sender, EventArgs e)
    {
        if (txtCustomerID.Text.Trim().Length == 5)
        {
            Customer newCustomer = new Customer(txtCompanyName.Text);
            newCustomer.SetAssignedIdTo(txtCustomerID.Text);
            newCustomer.ContactName = txtContactName.Text;

            IDaoFactory  daoFactory  = new NHibernateDaoFactory();
            ICustomerDao customerDao = daoFactory.GetCustomerDao();

            if (!IsDuplicateOfExisting(newCustomer, customerDao))
            {
                customerDao.Save(newCustomer);
                Response.Redirect("ListCustomers.aspx?action=added");
            }
            else
            {
                lblMessage.Text =
                    "<span style=\"color:red\">The ID you provided is already in use.</span><br />Please change the ID and try again.";
            }
        }
        else
        {
            lblMessage.Text =
                "<span style=\"color:red\">The ID you provide must be exactly 5 characters long.</span><br />Please change the ID and try again.";
        }
    }
Пример #4
0
        public string CreateCustomer(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            if (customer.ID.Length == 5)
            {
                if (!IsDuplicateOfExisting(customer))
                {
                    customerDao.Save(customer);
                }
                else
                {
                    return
                        ("<span style=\"color:red\">The ID you provided is already in use.</span><br />Please change the ID and try again.");
                }
            }
            else
            {
                return
                    ("<span style=\"color:red\">The ID you provide must be exactly 5 characters long.</span><br />Please change the ID and try again.");
            }

            return(string.Empty);
        }
Пример #5
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);
            }
        }
Пример #6
0
        public IActionResult Save([FromBody] Customer customer, [FromServices] CustomerDb db)
        {
            if (customer == null)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, new { error = "cannot store null entity" }));
            }
            int rowId = _dao.Save(customer, db);

            if (rowId <= 0)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = "error occurred while saving customer" }));
            }
            return(CreatedAtAction(nameof(CustomerController.GetById), nameof(CustomerController).RemoveSuffix("Controller"), new { id = rowId }, customer));
        }
Пример #7
0
 public void Save(Customer customer)
 {
     _customerDao.Save(customer);
 }