예제 #1
0
 public void Register(int moduleId, int year, byte term)
 {
     ModuleRegistration reg;
     try
     {
         var person = Session["Person"] as Person;
         var module = modulesRepository.GetBy(moduleId);
         var availability = modulesRepository.GetAvailabilityOf(module, year, term);
         reg = new ModuleRegistration(person, availability);
         modulesRepository.SaveRegistraion(reg);
         RenderText(reg.Id.ToString());
     }
     catch (Exception exception)
     {
         Response.StatusCode = 500;
         RenderText("ERR");
     }
 }
예제 #2
0
        public void CanRegister()
        {
            ActiveRecordStarter.Initialize(typeof(Module).Assembly, ActiveRecordSectionHandler.Instance);

            var factory = ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof(ActiveRecordBase));
            var repo = new ModulesRepository { SessionFactory = factory };
            var session = factory.OpenSession();
            NHibernate.Context.CurrentSessionContext.Bind(session);
            var person = session.CreateQuery("from Person").SetMaxResults(1).UniqueResult<Person>();
            Console.WriteLine(person.Id);
            var moduleAvailability = session.CreateQuery("from ModuleAvailability ma").SetMaxResults(1).UniqueResult<ModuleAvailability>();
            var reg = new ModuleRegistration(person, moduleAvailability);
            repo.SaveRegistraion(reg);

            session.Flush();
            session.Clear();
            Console.WriteLine(reg.ToString());

            var r = session.CreateQuery("from ModuleRegistration r where r.Student = :student")
                .SetEntity("student", person)
                .UniqueResult<ModuleRegistration>();

            Console.WriteLine(r.ToString());
        }