public ActionResult My(int id)
        {
            var building = buildingsRepository.GetById(id);
            if (building == null) {
                return HttpNotFound();
            }

            var submitter = personsRepository.GetPersonByUsername(User.Identity.Name);
            var maintenances = maintenancesRepository.GetAllMaintenancesBySubmitter(submitter, building.Id);
            var newMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.NotStarted);
            var activeMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.InProgress);
            var inConfirmationMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.InConfirmation);
            var completedMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.Completed);

            LinksModel links = new LinksModel();
            if(Session["lastPageId"] != null) {
                links.Id = (int) Session["lastPageId"];
                links.Links = NavLinksGenerator.GetOwnerLinks(building, "Moji kvarovi");
            }

            var model = new IndexModel() {
                NewMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(newMaintenances),
                ActiveMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(activeMaintenances),
                InConfirmationMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(inConfirmationMaintenances),
                CompletedMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(completedMaintenances),
                Roles = Roles.GetRolesForUser(),
                CurrentRole = "owner",
                Links = links,
                Building = Mapper.Map<Building, BuildingListModel>(building)
            };

            return View("Index", model);
        }
        public ActionResult Index(int id)
        {
            if (User.IsInRole("contractor")) { return new HttpUnauthorizedResult(); }

            var building = buildingsRepository.GetById(id);
            if(building == null) {
                return HttpNotFound();
            }

            var maintenances = maintenancesRepository.GetAllMaintenancesByBuilding(building.Id);
            var newMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.NotStarted);
            var activeMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.InProgress);
            var inConfirmationMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.InConfirmation);
            var completedMaintenances = maintenances.Where(m => m.StatusOfMaintenance == StatusOfMaintenance.Completed);

            LinksModel links = new LinksModel();
            if (Session["lastPageId"] != null) {
                links.Id = (int)Session["lastPageId"];
            }

            string role = (string)Session["role"] ?? string.Empty;
            if (role == "representative") {
                links.Links = NavLinksGenerator.GetRepresentativeLinks(building, "Kvarovi");
            } else if (role == "buildingmanager") {
                links.Links = NavLinksGenerator.GetManagerLinks(building, "Kvarovi");
            } else if (role == "owner") {
                links.Links = NavLinksGenerator.GetOwnerLinks(building, "Kvarovi");
            }

            var model = new IndexModel() {
                NewMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(newMaintenances),
                ActiveMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(activeMaintenances),
                InConfirmationMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(inConfirmationMaintenances),
                CompletedMaintenances = Mapper.Map<IEnumerable<Maintenance>, IEnumerable<MaintenanceDetailModel>>(completedMaintenances),
                Roles = Roles.GetRolesForUser(),
                CurrentRole = role,
                Links = links,
                Building = Mapper.Map<Building, BuildingListModel>(building)
            };

            return View(model);
        }