public static BuildingManager getBuildingManager()
        {
            LegalPerson legalPerson = new LegalPerson("12345678902", "Upravitelj");
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            return buildingManager;
        }
        public void Can_Add_Contractors_To_BuildingManager()
        {
            // Arrange
            LegalPerson legalPersonForContractor1 = new LegalPerson("12345678902", "Contractor 1 d.o.o.");
            Contractor contractor1 = new Contractor(legalPersonForContractor1);
            LegalPerson legalPersonForContractor2 = new LegalPerson("12345678903", "Contractor 2 d.o.o.");
            Contractor contractor2 = new Contractor(legalPersonForContractor2);

            Contractor[] contractors = new Contractor[] {
                contractor1,
                contractor2
            };

            LegalPerson legalPersonForContractor3 = new LegalPerson("12345678904", "Contractor 3 d.o.o.");
            Contractor contractor3 = new Contractor(legalPersonForContractor3);

            LegalPerson legalPersonForManager = new LegalPerson("12345678901", "Mile d.o.o.");

            // Act
            BuildingManager buildingManager = new BuildingManager(legalPersonForManager, contractors);
            buildingManager.AddContractor(contractor3);

            // Assert
            Assert.AreEqual(3, buildingManager.Contractors.Count);
            Assert.AreEqual(contractor1, buildingManager.Contractors.ElementAt(0));
            Assert.AreEqual(contractor2, buildingManager.Contractors.ElementAt(1));
            Assert.AreEqual(contractor3, buildingManager.Contractors.ElementAt(2));
        }
        public void Can_Save_BuildingManager_To_DB()
        {
            // Arrange
            LegalPerson legalPerson = new LegalPerson("12345678901", "Ime");
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            BuildingManagersNHRepository buildingManagersNhRepository = new BuildingManagersNHRepository(SessionFactory);

            // Act
            using (var session = SessionFactory.OpenSession()) {
                using (var tx = Session.BeginTransaction()) {
                    buildingManagersNhRepository.SaveOrUpdate(buildingManager);
                    tx.Commit();
                }

            }

            IList<BuildingManager> managers = null;
            using (var session = SessionFactory.OpenSession()) {
                using (var tx = Session.BeginTransaction()) {
                    managers = buildingManagersNhRepository.GetAll().ToList();
                    tx.Commit();
                }

            }

            // Assert
            Assert.IsTrue(managers.Count > 0, "Contractor has been saved to database.");
        }
        public void Can_Remove_Service_From_Contractor()
        {
            LegalPerson legalPersonForContractor1 = new LegalPerson("12345678902", "Contractor 1 d.o.o.");
            Contractor contractor1 = new Contractor(legalPersonForContractor1);
            LegalPerson legalPersonForContractor2 = new LegalPerson("12345678903", "Contractor 2 d.o.o.");
            Contractor contractor2 = new Contractor(legalPersonForContractor2);
            LegalPerson legalPersonForContractor3 = new LegalPerson("12345678904", "Contractor 3 d.o.o.");
            Contractor contractor3 = new Contractor(legalPersonForContractor3);

            Contractor[] contractors = new Contractor[] {
                contractor1,
                contractor2,
                contractor3
            };

            LegalPerson legalPersonForManager = new LegalPerson("12345678901", "Mile d.o.o.");

            BuildingManager buildingManager = new BuildingManager(legalPersonForManager, contractors);

            // Act
            buildingManager.RemoveContractor(contractor2);

            // Assert
            Assert.AreEqual(2, buildingManager.Contractors.Count);
            Assert.AreEqual(contractor1, buildingManager.Contractors.ElementAt(0));
            Assert.AreEqual(contractor3, buildingManager.Contractors.ElementAt(1));
        }
        public void Can_Save_Bill_To_Db()
        {
            // Arrange
            City city = new City(10000, "Zagreb");
            Cadastre cadastre = new Cadastre("Trnje", "12345", city);
            CadastralParticle cadastralParticle = new CadastralParticle(cadastre, "123", 23, "Opis");
            LandRegistry landRegistry = new LandRegistry(cadastralParticle);

            var person = new PhysicalPerson("12345678901", "Ime", "Prezime") {
                Address = new Address("Ulica", "1", city)
            };

            var partitionSpace = landRegistry.CreatePartitionSpace("123", 12, "Opis etaže", person);

            LegalPerson legalPerson = new LegalPerson("12345678902", "Ime") {
                NumberOfBankAccount = "123456",
                Address = new Address("Ulica", "2", city)
            };
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            Building building = new Building(buildingManager) {
                LandRegistry = landRegistry
            };

            Bill bill = new Bill(legalPerson, building.Reserve, "opis plaćanja", 23) {
                ReferenceNumber = "123"
            };
            bill.AddBillItem(new BillItem(1, 12.3m, "Opis"));

            IBillsRepository billsRepository = new BillsNHRepository(SessionFactory);

            // Act
            using (var session = SessionFactory.OpenSession()) {
                using (var transaction = session.BeginTransaction()) {
                    session.Save(city);
                    session.Save(person);
                    session.Save(legalPerson);
                    session.Save(cadastre);
                    session.Save(landRegistry);
                    session.Save(buildingManager);
                    session.Save(building);

                    billsRepository.SaveOrUpdate(bill);

                    transaction.Commit();
                }
            }

            IList<Bill> billsFromDb = null;
            using (var session = SessionFactory.OpenSession()) {
                using (var transaction = session.BeginTransaction()) {
                    billsFromDb = billsRepository.GetAll().ToList();
                    transaction.Commit();
                }
            }

            // Assert
            Assert.IsTrue(billsFromDb.Count == 1, "No Bill from database.");
        }
예제 #6
0
        public static BuildingManager getBuildingManager()
        {
            LegalPerson legalPerson = new LegalPerson("12345678902", "Upravitelj") {
                NumberOfBankAccount = "1234567"
            };
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            return buildingManager;
        }
        public void Can_Save_Maintenance_To_DB()
        {
            // Arrange
            var person = new PhysicalPerson("12345678901", "Ime", "Prezime");
            MaintenanceRequest maintenanceRequest = new MaintenanceRequest(
                person
                , "Kvar na grijanju"
                , "Grijanje ne radi"
                , "Prvi kat, stan 2");

            City city = new City(10000, "Zagreb");
            Cadastre cadastre = new Cadastre("Trnje", "12345", city);
            CadastralParticle cadastralParticle = new CadastralParticle(cadastre, "123", 23, "Opis");
            LandRegistry landRegistry = new LandRegistry(cadastralParticle);

            var partitionSpace = landRegistry.CreatePartitionSpace("123", 12, "Opis etaže", person);

            LegalPerson legalPerson = new LegalPerson("12345678902", "Ime");
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            Building building = new Building(buildingManager) {
                LandRegistry = landRegistry
            };

            RepairService repairService = new RepairService("Popravak grijanja");

            Maintenance maintenance = new Maintenance(maintenanceRequest, Urgency.Normal, repairService, building);

            IMaintenancesRepository maintenancesRepository = new MaintenancesNHRepository(SessionFactory);

            // Act
            IList<Maintenance> maintenancesFromDb = null;
            using (var session = SessionFactory.OpenSession()) {
                using (var tx = session.BeginTransaction()) {
                    session.Save(person);
                    session.Save(city);
                    session.Save(legalPerson);
                    session.Save(cadastre);
                    session.Save(landRegistry);
                    session.Save(buildingManager);
                    session.Save(building);
                    session.Save(repairService);

                    maintenancesRepository.SaveOrUpdate(maintenance);

                    tx.Commit();
                }

                using (var tx = session.BeginTransaction()) {
                    maintenancesFromDb = maintenancesRepository.GetAll().ToList();
                    tx.Commit();
                }
            }

            // Assert
            Assert.IsTrue(maintenancesFromDb.Count == 1, "No Maintenance from database.");
        }
        public void Can_Read_Reserve_From_Db()
        {
            // Arrange
            City city = new City(10000, "Zagreb");
            Cadastre cadastre = new Cadastre("Trnje", "12345", city);
            CadastralParticle cadastralParticle = new CadastralParticle(cadastre, "123", 23, "Opis");
            LandRegistry landRegistry = new LandRegistry(cadastralParticle);

            var person = new PhysicalPerson("12345678901", "Ime", "Prezime");
            var partitionSpace = landRegistry.CreatePartitionSpace("123", 12, "Opis etaže", person);

            LegalPerson legalPerson = new LegalPerson("12345678902", "Ime") {
                NumberOfBankAccount = "12332213",
                Address = new Address("dsa", "2", city)
            };
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            Building building = new Building(buildingManager) {
                LandRegistry = landRegistry
            };

            Bill bill = new Bill(legalPerson, building.Reserve, "račun", 23) {
                ReferenceNumber = "123"
            };
            building.Reserve.AddBillForPayment(bill);

            // Act
            using (var session = SessionFactory.OpenSession()) {
                using (var transaction = session.BeginTransaction()) {
                    session.Save(city);
                    session.Save(cadastre);
                    session.Save(person);
                    session.Save(landRegistry);
                    session.Save(legalPerson);
                    session.Save(buildingManager);
                    session.Save(building);

                    transaction.Commit();
                }
            }

            IReservesRepository reservesRepository = new ReservesNHRepository(SessionFactory);
            IList<Reserve> reservesFromDb = null;
            using (var session = SessionFactory.OpenSession()) {
                using (var transaction = session.BeginTransaction()) {
                    reservesFromDb = reservesRepository.GetAll().ToList();
                    transaction.Commit();
                }
            }

            // Assert
            Assert.IsTrue(reservesFromDb.Count == 1, "No Reserves from database.");
            //Assert.IsTrue(reservesFromDb[0].ReserveBills.Count == 1);
        }
        public void Can_Save_AdminJobsVoting_To_DB()
        {
            // Arrange
            City city = new City(10000, "Zagreb");
            Cadastre cadastre = new Cadastre("Trnje", "12345", city);
            CadastralParticle cadastralParticle = new CadastralParticle(cadastre, "123", 23, "Opis");
            LandRegistry landRegistry = new LandRegistry(cadastralParticle);

            var person = new PhysicalPerson("12345678901", "Ime", "Prezime");
            var partitionSpace = landRegistry.CreatePartitionSpace("123", 12, "Opis etaže", person);

            LegalPerson legalPerson = new LegalPerson("12345678902", "Ime");
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            Building building = new Building(buildingManager) {
                LandRegistry = landRegistry
            };

            AdministrationJobsVoting administrationJobsVoting = new AdministrationJobsVoting(
                AdministrationJobsType.Regular,
                building,
                "Subject",
                "Description",
                new DateTime(2011, 11, 11));

            AdminJobsVotingsNHRepository adminJobsVotingsNhRepository = new AdminJobsVotingsNHRepository(SessionFactory);

            // Act
            AdministrationJobsVoting adminJobsVotingFromDb = null;
            using (var session = SessionFactory.OpenSession()) {
                using (var tx = session.BeginTransaction()) {
                    session.Save(city);
                    session.Save(person);
                    session.Save(legalPerson);
                    session.Save(cadastre);
                    session.Save(landRegistry);
                    session.Save(buildingManager);
                    session.Save(building);

                    adminJobsVotingsNhRepository.SaveOrUpdate(administrationJobsVoting);
                    tx.Commit();
                }

                using (var tx = session.BeginTransaction()) {
                    adminJobsVotingFromDb = adminJobsVotingsNhRepository.GetById(administrationJobsVoting.Id);
                    tx.Commit();
                }
            }

            // Assert
            Assert.AreEqual(administrationJobsVoting, adminJobsVotingFromDb, "Two administration jobs voting entities aren't equal.");
        }
        public void Can_Create_BuildingManager()
        {
            // Arrange
            LegalPerson legalPerson = new LegalPerson("12345678901", "Mile d.o.o.");

            // Act
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            // Assert
            Assert.IsNotNull(buildingManager);
            Assert.AreEqual(legalPerson, buildingManager.LegalPerson);
            Assert.IsFalse(buildingManager.Contractors.Any());
        }
        public void SetUp()
        {
            cadastre = new Cadastre("Trešnjevka", "332134", new City(10000, "Zagreb"));
            cadastralParticle = new CadastralParticle(cadastre, "123", 120, "opis");
            landRegistry = new LandRegistry(cadastralParticle);

            var buildingManager = new BuildingManager(new LegalPerson("12345678903", "Upravitelj"));

            building = new Building(buildingManager) {
                LandRegistry = landRegistry
            };

            partitionSpace1 = landRegistry.CreatePartitionSpace("123", 23, "Stan 1", new PhysicalPerson("12345678903", "Mile1", "Milic"));
            partitionSpace2 = landRegistry.CreatePartitionSpace("123", 23, "Stan 2", new PhysicalPerson("12345678904", "Mile2", "Milic"));
            partitionSpace3 = landRegistry.CreatePartitionSpace("123", 23, "Stan 3", new PhysicalPerson("12345678905", "Mile3", "Milic"));
            partitionSpace4 = landRegistry.CreatePartitionSpace("123", 23, "Stan 4", new PhysicalPerson("12345678906", "Mile4", "Milic"));
        }
        public void Can_Save_Building_To_DB()
        {
            // Arrange
            City city = new City(10000, "Zagreb");
            Cadastre cadastre = new Cadastre("Trnje", "12345", city);
            CadastralParticle cadastralParticle = new CadastralParticle(cadastre, "123", 23, "Opis");
            LandRegistry landRegistry = new LandRegistry(cadastralParticle);

            var person = new PhysicalPerson("12345678901", "Ime", "Prezime");
            var partitionSpace = landRegistry.CreatePartitionSpace("123", 12, "Opis etaže", person);

            LegalPerson legalPerson = new LegalPerson("12345678902", "Ime");
            BuildingManager buildingManager = new BuildingManager(legalPerson);

            Building building = new Building(buildingManager) {
                LandRegistry = landRegistry
            };

            BuildingsNHRepository buildingsNhRepository = new BuildingsNHRepository(SessionFactory);

            // Act
            Building buildingFromDb = null;
            using (var session = SessionFactory.OpenSession()) {
                using (var tx = session.BeginTransaction()) {
                    session.Save(city);
                    session.Save(person);
                    session.Save(legalPerson);
                    session.Save(cadastre);
                    session.Save(landRegistry);
                    session.Save(buildingManager);

                    buildingsNhRepository.SaveOrUpdate(building);
                    tx.Commit();
                }

                using (var tx = session.BeginTransaction()) {
                    buildingFromDb = buildingsNhRepository.GetById(building.Id);
                    tx.Commit();
                }
            }

            // Assert
            Assert.AreEqual(building, buildingFromDb, "Two building entities aren't equal.");
        }
        public ActionResult RegisterManager(RegisterManagerUserModel managerModel)
        {
            if (ModelState.IsValid) {
                Person person = personsRepository.GetByOib(managerModel.Oib);
                bool isUserExistingForPerson = false;
                if(person != null) {
                    var existingUser = housingMgmtUsersRepository.GetUserByPerson(person);
                    isUserExistingForPerson = existingUser != null;
                }

                if (!isUserExistingForPerson) {

                    MembershipCreateStatus createStatus;
                    NHibernateMembershipUser membershipUser =
                        Membership.CreateUser(managerModel.UserName, managerModel.Password, managerModel.Email,
                                              null, null, true, null, out createStatus) as NHibernateMembershipUser;

                    if (createStatus == MembershipCreateStatus.Success) {
                        if (person == null) {
                            City city = citiesRepository.GetById(managerModel.City);
                            person = new LegalPerson(managerModel.Oib, managerModel.Name) {
                                NumberOfBankAccount = managerModel.NumberOfBankAccount,
                                Address = new Address(managerModel.StreetAddress, managerModel.StreetAddressNumber, city)
                            };

                            if (!string.IsNullOrEmpty(managerModel.TelephoneNumber)) {
                                person.AddTelephone(new Telephone("Telefon", managerModel.TelephoneNumber));
                            }

                            if (!string.IsNullOrEmpty(managerModel.MobileNumber)) {
                                person.AddTelephone(new Telephone("Mobitel", managerModel.MobileNumber));
                            }
                        }

                        if (person is LegalPerson) {
                            BuildingManager buildingManager = null;

                            try {
                                membershipUser.User.Person = person;

                                var managerRole = rolesRepository.GetRole("buildingmanager");
                                membershipUser.User.AddRole(managerRole);

                                var partitionSpaces = partitionSpacesRepository.GetPartitionSpaces(person);
                                if (partitionSpaces.Count > 0) {
                                    var ownerRole = rolesRepository.GetRole("owner");
                                    membershipUser.User.AddRole(ownerRole);
                                }

                                LegalPerson legalPerson = (LegalPerson) person;
                                buildingManager = new BuildingManager(legalPerson);

                                FormsAuthentication.SetAuthCookie(managerModel.UserName, false);
                                buildingManagersRepository.SaveOrUpdate(buildingManager);
                                emailNotifier.NotifyOfRegistration(membershipUser.User);
                                return RedirectToAction("index", "dashboard");

                            } catch (BusinessRulesException ex) {
                                ex.CopyTo(ModelState);
                            }
                        } else {
                            ModelState.AddModelError("Oib", "Osoba sa ovim OIB-om je već upisana te nije pravna osoba.");
                        }

                    } else {
                        ModelState.AddModelError("", errorCodeToString(createStatus));
                    }
                } else {
                    ModelState.AddModelError("", "Navedena osoba već ima kreiran korisnički račun.");
                }
            }

            managerModel.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name", managerModel.City);

            return View(managerModel);
        }
예제 #14
0
 /// <summary>
 /// Konstruktor
 /// </summary>
 /// <param name="buildingManager">upravitelj zrade</param>
 public Building(BuildingManager buildingManager)
 {
     SetBuildingManager(buildingManager);
     reserve = new Reserve(this);
 }
예제 #15
0
        /// <summary>
        /// Postavlja upravitelja zgrade
        /// </summary>
        /// <param name="buildingManager"></param>
        public virtual void SetBuildingManager(BuildingManager buildingManager)
        {
            if (buildingManager == null) {
                throw new BuildingMustHaveBuildingManagerException();
            }

            this.buildingManager = buildingManager;
        }