Exemplo n.º 1
0
    private void DisplayAllSuppliers()
    {
        ISupplierDao supplierDao = new NHibernateDaoFactory().GetSupplierDao();

        grdSuppliers.DataSource = supplierDao.GetAll();
        grdSuppliers.DataBind();
    }
    private void ShowProductsOrdered(Customer customer) {
        IDaoFactory daoFactory = new NHibernateDaoFactory();
        IHistoricalOrderSummaryDao orderSummaryDao = daoFactory.GetHistoricalOrderSummaryDao();

        grdProductsOrdered.DataSource = orderSummaryDao.GetCustomerOrderHistoryFor(customer.ID);
        grdProductsOrdered.DataBind();
    }
 public void CanGetCustomerOrderHistory()
 {
     IDaoFactory daoFactory = new NHibernateDaoFactory();
     IHistoricalOrderSummaryDao historicalOrderSummaryDao = daoFactory.GetHistoricalOrderSummaryDao();
     List<HistoricalOrderSummary> foundSummaries = historicalOrderSummaryDao.GetCustomerOrderHistoryFor(TestGlobals.TestCustomer.ID);
     Assert.AreEqual(11, foundSummaries.Count);
 }
 public void CanGetByExample() {
     IDaoFactory daoFactory = new NHibernateDaoFactory();
     ICustomerDao customerDao = daoFactory.GetCustomerDao();
     Customer exampleCustomer = new Customer(TestGlobals.TestCustomer.CompanyName);
     Customer foundCustomer = customerDao.GetUniqueByExample(exampleCustomer);
     Assert.AreEqual(TestGlobals.TestCustomer.CompanyName, foundCustomer.CompanyName);
 }
        public void TestGetById() {
            IDaoFactory daoFactory = new NHibernateDaoFactory();
            ICustomerDao customerDao = daoFactory.GetCustomerDao();

            Customer foundCustomer = customerDao.GetById(TestGlobals.TestCustomer.ID, false);
            Assert.AreEqual(TestGlobals.TestCustomer.CompanyName, foundCustomer.CompanyName);
        }
    private void DisplayAllSuppliers() {
        IDaoFactory daoFactory = new NHibernateDaoFactory();
        ISupplierDao supplierDao = daoFactory.GetSupplierDao();

        grdSuppliers.DataSource = supplierDao.GetAll();
        grdSuppliers.DataBind();
    }
 public void can_delete_autor()
 {
     IAutorDao autorDao = new NHibernateDaoFactory().getAutorDao();
     Autor a = autorDao.GetById(147L, true);
     if(a != null)
         autorDao.delete(a);
 }
    private void DisplayAllCustomers() {
        IDaoFactory daoFactory = new NHibernateDaoFactory();
        ICustomerDao customerDao = daoFactory.GetCustomerDao();

        grdEmployees.DataSource = customerDao.GetAll();
        grdEmployees.DataBind();
    }
Exemplo n.º 9
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.";
        }
    }
        public void CanGetCustomerOrderHistory()
        {
            IDaoFactory daoFactory = new NHibernateDaoFactory();
            IHistoricalOrderSummaryDao    historicalOrderSummaryDao = daoFactory.GetHistoricalOrderSummaryDao();
            List <HistoricalOrderSummary> foundSummaries            = historicalOrderSummaryDao.GetCustomerOrderHistoryFor(TestGlobals.TestCustomer.ID);

            Assert.AreEqual(11, foundSummaries.Count);
        }
Exemplo n.º 11
0
    private void DisplayAllCustomers()
    {
        IDaoFactory  daoFactory  = new NHibernateDaoFactory();
        ICustomerDao customerDao = daoFactory.GetCustomerDao();

        grdEmployees.DataSource = customerDao.GetAll();
        grdEmployees.DataBind();
    }
Exemplo n.º 12
0
    private void ShowProductsOrdered(Customer customer)
    {
        IDaoFactory daoFactory = new NHibernateDaoFactory();
        IHistoricalOrderSummaryDao orderSummaryDao = daoFactory.GetHistoricalOrderSummaryDao();

        grdProductsOrdered.DataSource = orderSummaryDao.GetCustomerOrderHistoryFor(customer.ID);
        grdProductsOrdered.DataBind();
    }
Exemplo n.º 13
0
        public void CanGetByExample()
        {
            IDaoFactory  daoFactory      = new NHibernateDaoFactory();
            ICustomerDao customerDao     = daoFactory.GetCustomerDao();
            Customer     exampleCustomer = new Customer(TestGlobals.TestCustomer.CompanyName);
            Customer     foundCustomer   = customerDao.GetUniqueByExample(exampleCustomer);

            Assert.AreEqual(TestGlobals.TestCustomer.CompanyName, foundCustomer.CompanyName);
        }
Exemplo n.º 14
0
        public void TestGetById()
        {
            IDaoFactory  daoFactory  = new NHibernateDaoFactory();
            ICustomerDao customerDao = daoFactory.GetCustomerDao();

            Customer foundCustomer = customerDao.GetById(TestGlobals.TestCustomer.ID, false);

            Assert.AreEqual(TestGlobals.TestCustomer.CompanyName, foundCustomer.CompanyName);
        }
Exemplo n.º 15
0
        public static void append(long tID, long pID)
        {
            IDaoFactory daoFactory = new NHibernateDaoFactory();

            Track track = daoFactory.getTrackDao().GetById(tID, false);
            Playlist playlist = daoFactory.getPlaylistDao().GetById(pID, false);

            playlist.addEinsatz( new Einsatz( playlist, track ));
            Playlist_Service.updatePositions(playlist);
        }
    private void DisplayCustomerToEdit() {
        IDaoFactory daoFactory = new NHibernateDaoFactory();
        ICustomerDao customerDao = daoFactory.GetCustomerDao();

        // No need to lock the customer since we're just viewing the data
        Customer customerToEdit = customerDao.GetById(Request.QueryString["customerID"], false);

        ShowCustomerDetails(customerToEdit);
        ShowPastOrders(customerToEdit);
        ShowProductsOrdered(customerToEdit);
    }
    private void UpdateCustomer() {
        IDaoFactory daoFactory = new NHibernateDaoFactory();
        ICustomerDao customerDao = daoFactory.GetCustomerDao();

        // Now that we're about to update the customer, be sure to lock the entity
        Customer customerToUpdate = customerDao.GetById(hidCustomerID.Value, true);

        // Changes to the customer object will be automatically committed at the end of the HTTP request
        customerToUpdate.CompanyName = txtCompanyName.Text;
        customerToUpdate.ContactName = txtContactName.Text;
    }
 public void initialise()
 {
     long id = QueryID.getValidated(this.view.QueryId);
     Playlist p = new NHibernateDaoFactory().getPlaylistDao().GetById(id, false);
     IList<Track> tracks = new List<Track>();
     if(p != null) {
         foreach(Einsatz e in p.Einsaetze)
             tracks.Add(e.Track);
         this.view.Playlist = p;
     }
     this.view.Tracks = tracks;
 }
Exemplo n.º 19
0
    private void UpdateCustomer()
    {
        IDaoFactory  daoFactory  = new NHibernateDaoFactory();
        ICustomerDao customerDao = daoFactory.GetCustomerDao();

        // Now that we're about to update the customer, be sure to lock the entity
        Customer customerToUpdate = customerDao.GetById(hidCustomerID.Value, true);

        // Changes to the customer object will be automatically committed at the end of the HTTP request
        customerToUpdate.CompanyName = txtCompanyName.Text;
        customerToUpdate.ContactName = txtContactName.Text;
    }
        public void TestGetOrdersShippedTo() {
            IDaoFactory daoFactory = new NHibernateDaoFactory();
            ICustomerDao customerDao = daoFactory.GetCustomerDao();

            Customer customer = customerDao.GetById(TestGlobals.TestCustomer.ID, false);
            // Give the customer its DAO dependency via a public setter
            customer.OrderDao = daoFactory.GetOrderDao();
            IList<Order> ordersMatchingDate = customer.GetOrdersOrderedOn(new DateTime(1998, 3, 10));

            Assert.AreEqual(1, ordersMatchingDate.Count);
            Assert.AreEqual(10937, ordersMatchingDate[0].ID);
        }
Exemplo n.º 21
0
    private void DisplayCustomerToEdit()
    {
        IDaoFactory  daoFactory  = new NHibernateDaoFactory();
        ICustomerDao customerDao = daoFactory.GetCustomerDao();

        // No need to lock the customer since we're just viewing the data
        Customer customerToEdit = customerDao.GetById(Request.QueryString["customerID"], false);

        ShowCustomerDetails(customerToEdit);
        ShowPastOrders(customerToEdit);
        ShowProductsOrdered(customerToEdit);
    }
Exemplo n.º 22
0
        public void CanGetOrdersShippedTo()
        {
            IDaoFactory  daoFactory  = new NHibernateDaoFactory();
            ICustomerDao customerDao = daoFactory.GetCustomerDao();
            IOrderDao    orderDao    = daoFactory.GetOrderDao();

            Customer customer = customerDao.GetById(TestGlobals.TestCustomer.ID, false);
            // Give the customer its DAO dependency via a public setter
            IList <Order> ordersMatchingDate = orderDao.GetOrdersOrderedOn(customer, new DateTime(1998, 3, 10));

            Assert.AreEqual(1, ordersMatchingDate.Count);
            Assert.AreEqual(10937, ordersMatchingDate[0].ID);
        }
Exemplo n.º 23
0
        public static void persist(Playlist playlist, IList<Einsatz> einsaetze)
        {
            NHibernateDaoFactory daoFactory = new NHibernateDaoFactory();
            IPlaylistDao playlistDao = daoFactory.getPlaylistDao();
            ITrackDao trackDao = daoFactory.getTrackDao();
            IEinsatzDao einsatzDao = daoFactory.getEinsatzDao();

            playlistDao.save(playlist);
            foreach(Einsatz einsatz in einsaetze) {
                einsatz.Track = trackDao.save(einsatz.Track);
                einsatzDao.save(einsatz);
            }
        }
 public virtual void init()
 {
     NHibernateDaoFactory df = new NHibernateDaoFactory();
     this.view.AutorList = df.getAutorDao().getAllSortedBy(true, Autor.Property.Name.ToString());
     this.view.BpmList = df.getBpmDao().getAllSortedBy(true, Bpm.Property.Value.ToString());
     this.view.CodeList = df.getCodeDao().getAllSortedBy(true, Code.Property.Name.ToString());
     this.view.EndingList = new List<Ending.Attribute>(Enum.GetValues(typeof(Ending.Attribute)) as IEnumerable<Ending.Attribute>);
     this.view.InterpretList = df.getInterpretDao().getAllSortedBy(true, Interpret.Property.Name.ToString());
     this.view.LabelList = df.getLabelDao().getAllSortedBy(true, Label.Property.Name.ToString());
     this.view.LaengeList = df.getLaengeDao().getAllSortedBy(true, Laenge.Property.Dauer.ToString());
     this.view.TitelList = df.getTitelDao().getAllSortedBy(true, Titel.Property.Name.ToString());
     this.view.VerlagList = df.getVerlagDao().getAllSortedBy(true, Verlag.Property.Name.ToString());
     this.view.YearList = df.getYearDao().getAllSortedBy(true, Year.Property.Value.ToString());
 }
        public override void update()
        {
            Track original = dao.GetById(this.view.TrackToEditID, true);
            Track new1 = this.view.TrackToCreate;

            if(original.Equals(new1))
                return;

            // Does edited track already exist?
            ICriteria c = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(Track));
            c.Add(Example.Create(new1)).CreateCriteria("Autor").Add(Example.Create(new1.Autor));
            c.Add(Example.Create(new1)).CreateCriteria("Bpm").Add(Example.Create(new1.Bpm).ExcludeNone());
            c.Add(Example.Create(new1)).CreateCriteria("Interpret").Add(Example.Create(new1.Interpret));
            c.Add(Example.Create(new1)).CreateCriteria("Label").Add(Example.Create(new1.Label));
            c.Add(Example.Create(new1)).CreateCriteria("Code").Add(Example.Create(new1.Code));
            c.Add(Example.Create(new1)).CreateCriteria("Laenge").Add(Example.Create(new1.Laenge));
            c.Add(Example.Create(new1)).CreateCriteria("Titel").Add(Example.Create(new1.Titel));
            c.Add(Example.Create(new1)).CreateCriteria("Verlag").Add(Example.Create(new1.Verlag));
            c.Add(Example.Create(new1)).CreateCriteria("Year").Add(Example.Create(new1.Year).ExcludeNone());
            c.Add(Expression.Eq("Ending.Value", new1.Ending.Value));

            Track existing = c.UniqueResult<Track>();

            if(existing != null) {
                foreach(Einsatz einsatz in original.Einsaetze)
                    einsatz.Track = existing;
            }
            else {
                NHibernateDaoFactory df = new NHibernateDaoFactory();
                if(!original.Autor.Equals(new1.Autor))
                    original.Autor = df.getAutorDao().save(new1.Autor);
                original.Bpm = df.getBpmDao().save(new1.Bpm);
                if(!original.Code.Equals(new1.Code))
                    original.Code = df.getCodeDao().save(new1.Code);
                if(!original.Interpret.Equals(new1.Interpret))
                    original.Interpret = df.getInterpretDao().save(new1.Interpret);
                if(!original.Label.Equals(new1.Label))
                    original.Label = df.getLabelDao().save(new1.Label);
                if(!original.Laenge.Equals(new1.Laenge))
                    original.Laenge = df.getLaengeDao().save(new1.Laenge);
                if(!original.Titel.Equals(new1.Titel))
                    original.Titel = df.getTitelDao().save(new1.Titel);
                if(!original.Verlag.Equals(new1.Verlag))
                    original.Verlag = df.getVerlagDao().save(new1.Verlag);
                original.Year = df.getYearDao().save(new1.Year);
                original.Ending.Value = new1.Ending.Value;
            }
        }
    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.";
        }
    }
Exemplo n.º 27
0
        public void replace(ISet<long> replaceable, long replacement)
        {
            ITrackDao trackDao = new NHibernateDaoFactory().getTrackDao();

            Track substitue = trackDao.GetById(replacement, true);

            ISession s = NHibernateSessionManager.Instance.GetSession();
            IList<Track> tracks = s.CreateQuery("from Track t where t.Id in (:idList)").SetParameterList("idList", replaceable).List<Track>();

            IList<Einsatz> updateableEinsaetze = s.CreateQuery("from Einsatz e where e.Track in (:tracks)")
                .SetParameterList("tracks", tracks)
                .List<Einsatz>();

            foreach(Einsatz einsatz in updateableEinsaetze)
                einsatz.Track = substitue;

            trackDao.commitChanges();

            foreach(Track track in tracks)
                trackDao.delete(track);

            trackDao.commitChanges();
        }
Exemplo n.º 28
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if(IsPostBack)
         daoFactory = new NHibernateDaoFactory();
 }