public ActionResult Edit(EditModel editModel)
        {
            if (ModelState.IsValid) {
                var person = personsRepository.GetPersonByUsername(User.Identity.Name);
                if (person == null) {
                    return HttpNotFound();
                }

                person.Name = editModel.Name;

                if (!string.IsNullOrEmpty(editModel.Surname) && person is PhysicalPerson) {
                    (person as PhysicalPerson).Surname = editModel.Surname;
                }

                var city = citiesRepository.GetById(editModel.Address.City.Id);
                var address = new Address(editModel.Address.StreetAddress, editModel.Address.StreetAddressNumber, city);
                person.Address = address;

                if (!string.IsNullOrEmpty(editModel.TelephoneNumber)) {
                    person.AddTelephone(new Telephone("Telefon", editModel.TelephoneNumber));
                } else if (!string.IsNullOrEmpty(editModel.MobileNumber)) {
                    person.AddTelephone(new Telephone("Mobitel", editModel.MobileNumber));
                }

                NHibernateMembershipUser user = Membership.GetUser() as NHibernateMembershipUser;
                user.User.Email = editModel.Email;

                if (!string.IsNullOrEmpty(editModel.Password) && !string.IsNullOrEmpty(editModel.ConfirmPassword) &&
                    editModel.Password.Equals(editModel.ConfirmPassword)) {
                    var membershipProvider = Membership.Provider;
                    var isPasswordChanged = membershipProvider.ChangePassword(User.Identity.Name, editModel.OldPassword, editModel.Password);
                    if (!isPasswordChanged) {
                        ModelState.AddModelError("OldPassword", "Unjeli ste neispravnu trenutnu lozinku.");
                        editModel.Address.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name", editModel.Address.City.Id);
                        editModel.Roles = Roles.GetRolesForUser();
                        editModel.UserName = User.Identity.Name;
                        return View(editModel);
                    }
                }

                return RedirectToAction("index", "dashboard");

            }

            editModel.Address.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name", editModel.Address.City.Id);
            editModel.Roles = Roles.GetRolesForUser();
            editModel.UserName = User.Identity.Name;
            return View(editModel);
        }
        public ActionResult AddPartitionSpace(int id, string owned, AddPartitionSpaceModel addPartitionSpaceModel)
        {
            if (!User.IsInRole("buildingmanager")) { return new HttpUnauthorizedResult(); }

            LandRegistry landRegistry = landRegistriesRepository.GetById(id);
            if (ModelState.IsValid) {
                // provjeri da li vec postoji etaža sa istim brojem uloška
                IPartitionSpace existingPartitionSpace = partitionSpacesRepository.GetPartitionSpace(addPartitionSpaceModel.PartitionSpace.RegistryNumber);

                if (existingPartitionSpace == null) {
                    if(landRegistry != null) {
                        var partitionSpaceModel = addPartitionSpaceModel.PartitionSpace;
                        try {
                            if(string.IsNullOrEmpty(owned)) {
                                landRegistry.CreatePartitionSpace(partitionSpaceModel.RegistryNumber, partitionSpaceModel.SurfaceArea,
                                                              partitionSpaceModel.Description);
                            } else {
                                Person owner = personsRepository.GetByOib(partitionSpaceModel.Owner.Oib);
                                var addressModel = partitionSpaceModel.Owner.Address;
                                var address = new Address(addressModel.StreetAddress, addressModel.StreetAddressNumber, citiesRepository.GetById(addressModel.City.Id));
                                if(string.IsNullOrEmpty(partitionSpaceModel.Owner.Surname)) {
                                    owner = owner ?? new LegalPerson(partitionSpaceModel.Owner.Oib, partitionSpaceModel.Owner.Name) {
                                        Address = address
                                    };
                                } else {
                                    owner = owner ?? new PhysicalPerson(partitionSpaceModel.Owner.Oib, partitionSpaceModel.Owner.Name,
                                        partitionSpaceModel.Owner.Surname) {
                                            Address = address
                                    };
                                }

                                var ownerRole = rolesRepository.GetRole("owner");
                                var newOwnerUser = housingMgmtUsersRepository.GetUserByPerson(owner);
                                if (newOwnerUser != null && !newOwnerUser.Roles.Contains(ownerRole)) {
                                    newOwnerUser.AddRole(ownerRole);
                                }

                                landRegistry.CreatePartitionSpace(partitionSpaceModel.RegistryNumber, partitionSpaceModel.SurfaceArea,
                                                              partitionSpaceModel.Description, owner);
                            }

                            return RedirectToAction("landregistry", new { id = landRegistry.Id });

                        } catch (BusinessRulesException ex) {
                            ex.CopyTo(ModelState);
                        }
                    } else {
                        return HttpNotFound();
                    }
                } else {
                    ModelState.AddModelError("PartitionSpace.RegistryNumber", "Etaža sa takvim brojem uloška već postoji.");
                }
            }

            var cadastralParticle = landRegistry.CadastralParticle;
            var building = buildingsRepository.GetByLandRegistry(landRegistry);
            addPartitionSpaceModel.PartitionSpace.CadastralParticle = Mapper.Map<CadastralParticle, CadastralParticleDetailModel>(cadastralParticle);
            addPartitionSpaceModel.Roles = Roles.GetRolesForUser();
            addPartitionSpaceModel.CurrentRole = "buildingmanager";
            addPartitionSpaceModel.Links = new LinksModel {Id = building.Id, Links = NavLinksGenerator.GetManagerLinks(building)};

            if (string.IsNullOrEmpty(owned)) {
                return View(addPartitionSpaceModel);
            } else {
                addPartitionSpaceModel.PartitionSpace.Owner.Address.Cities = new SelectList(citiesRepository.GetAll(), "Id", "Name");
                return View("AddOwnedPartitionSpace", addPartitionSpaceModel);
            }
        }