Beispiel #1
0
        public void DodajRadnika(string ime, string prezime, string email, int orgSemaId)
        {
            var sema = (from seme in NHibernateSession.Linq<OrganizacionaSema>()
                        where seme.OrganizacionaSemaId == orgSemaId
                        select seme).SingleOrDefault();

            var radnik = new Radnik();
            radnik.Ime = ime;
            radnik.Prezime = prezime;
            radnik.Email = email;
            radnik.OrganizacionaSema = sema;

            NHibernateSession.SaveOrUpdate(radnik);

            using (ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                try
                {
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
            }
        }
Beispiel #2
0
        public void DodajRadnikaTest()
        {
            var sema = new OrganizacionaSema();
            sema.ImeOrganizacioneSeme = "Test";
            sema.ImeOrganizacioneSemeSkraceno = "TST";

            var radnik = new Radnik();
            radnik.Ime = "Test";
            radnik.Prezime = "Test";
            radnik.Email = "*****@*****.**";
            radnik.OrganizacionaSema = sema;

            using (ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                NHibernateSession.Save(sema);
                NHibernateSession.Save(radnik);
                transaction.Commit();
            }

            var semaIzBaze = (from seme in NHibernateSession.Linq<OrganizacionaSema>()
                              where seme.OrganizacionaSemaId == sema.OrganizacionaSemaId
                              select seme).SingleOrDefault();

            Assert.IsNotNull(semaIzBaze);
            Assert.That(semaIzBaze.ImeOrganizacioneSeme == "Test");

            var radnikIzBaze = (from radnici in NHibernateSession.Linq<Radnik>()
                                where radnici.RadnikId == radnik.RadnikId
                                select radnici).SingleOrDefault();

            Assert.IsNotNull(radnikIzBaze);
            Assert.That(radnikIzBaze.Ime == "Test");
            Assert.That(radnikIzBaze.OrganizacionaSema.ImeOrganizacioneSeme == "Test");

            using (ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                NHibernateSession.Delete(radnikIzBaze);
                NHibernateSession.Delete(semaIzBaze);
                transaction.Commit();
            }

            semaIzBaze = (from seme in NHibernateSession.Linq<OrganizacionaSema>()
                              where seme.OrganizacionaSemaId == sema.OrganizacionaSemaId
                              select seme).SingleOrDefault();

            radnikIzBaze = (from radnici in NHibernateSession.Linq<Radnik>()
                            where radnici.RadnikId == radnik.RadnikId
                            select radnici).SingleOrDefault();

            Assert.IsNull(semaIzBaze);
            Assert.IsNull(radnikIzBaze);
        }
Beispiel #3
0
        public void AzurirajRadnika(Radnik radnik)
        {
            var r = (from radnici in NHibernateSession.Linq<Radnik>()
                          where radnici.RadnikId == radnik.RadnikId
                          select radnici).SingleOrDefault();

            NHibernateSession.SaveOrUpdate(r);

            using (ITransaction transaction = NHibernateSession.BeginTransaction())
            {
                try
                {
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
            }
        }