public ActionResult AddManager(int id, int managerId)
        {
            if (!User.IsInRole("representative")) {
                return new HttpUnauthorizedResult();
            }

            var building = buildingsRepository.GetById(id);

            // provjeri da li je trenutna osoba predstavnik suvlasnika zgrade
            var representative = building.RepresentativeOfPartOwners;
            var currentUser = housingMgmtUsersRepository.GetUserByPerson(representative);

            if (currentUser == null) {
                return new HttpUnauthorizedResult();
            }

            var newManager = buildingManagersRepository.GetById(managerId);
            var newManagerUser = housingMgmtUsersRepository.GetUserByPerson(newManager.LegalPerson);

            // novi predstavnik mora imati otvoren racun (biti korisnik)
            if (newManagerUser != null) {
                var role = rolesRepository.GetRole("buildingmanager");

                // makni ulogu postojecem predstavniku
                var currentManager = building.BuildingManager;
                if (currentManager != null) {
                    var currentManagerUser = housingMgmtUsersRepository.GetUserByPerson(currentManager.LegalPerson);
                    currentManagerUser.RemoveRole(role);
                }

                // postavi ulogu novom predstavniku
                newManagerUser.AddRole(role);
                building.SetBuildingManager(newManager);
                return RedirectToAction("building", new {id = id});

            } else {
                ModelState.AddModelError("",
                                         string.Format(
                                                       "Osoba {0} ne može biti postavljena za upravitelja zgrade jer nema kreiran korisnički račun.",
                                                       newManager.LegalPerson.FullName));

                var managers = buildingManagersRepository.GetAll()
                    .Except(new List<BuildingManager> {building.BuildingManager}).ToList();

                var model = new AddBuildingManagerModel() {
                    Managers = Mapper.Map<IList<BuildingManager>, IList<BuildingManagerModel>>(managers),
                    Roles = Roles.GetRolesForUser(),
                    Building = building.Address.StreetAddress + " " + building.Address.StreetAddressNumber,
                    BuildingId = building.Id,
                    CurrentRole = "representative",
                    Links = new LinksModel() {Id = building.Id,  Links = NavLinksGenerator.GetRepresentativeLinks(building, string.Empty)}
                };

                return View(model);
            }
        }
        public ActionResult AddManager(int id)
        {
            if (!User.IsInRole("representative")) { return new HttpUnauthorizedResult(); }

            var building = buildingsRepository.GetById(id);

            // provjeri da li je trenutna osoba predstavnik suvlasnika zgrade
            var representative = building.RepresentativeOfPartOwners;
            var currentUser = housingMgmtUsersRepository.GetUserByPerson(representative);

            if (currentUser == null) {
                return new HttpUnauthorizedResult();
            }

            var managers = buildingManagersRepository.GetAll()
                .Except(new List<BuildingManager> { building.BuildingManager}).ToList();

            var model = new AddBuildingManagerModel() {
                Managers = Mapper.Map<IList<BuildingManager>, IList<BuildingManagerModel>>(managers),
                Roles = Roles.GetRolesForUser(),
                Building = building.Address.StreetAddress + " " + building.Address.StreetAddressNumber,
                BuildingId = building.Id,
                CurrentRole = "representative",
                Links = new LinksModel() { Id = building.Id, Links = NavLinksGenerator.GetRepresentativeLinks(building, string.Empty)}
            };

            return View(model);
        }