public void Can_Take_Snapshot_Of_Person()
        {
            // Arrange
            LegalPerson person = new LegalPerson("12345678901", "Mile");
            Telephone telephone1 = new Telephone("Kucni telefon", "123456");
            Telephone telephone2 = new Telephone("Mobitel", "098123456");

            person.AddTelephone(telephone1);
            person.AddTelephone(telephone2);

            // Act
            var personSnapshot = new PersonSnapshot(person);

            // Assert
            Assert.AreEqual(person.Oib, personSnapshot.Oib);
            Assert.AreEqual(person.Name, personSnapshot.FullName);
            Assert.AreEqual(person.Address, personSnapshot.Address);
        }
        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);
        }