public ActionResult DelegateRepair(int id, DelegateRepairModel delegateRepairModel)
        {
            if (!User.IsInRole("buildingmanager")) { return new HttpUnauthorizedResult(); }

            var maintenance = maintenancesRepository.GetById(id);
            if (maintenance == null) { return HttpNotFound(); }
            if(maintenance.StatusOfMaintenance == StatusOfMaintenance.InProgress) {
                return new HttpStatusCodeResult(405);
            }

            BuildingManager buildingManager = maintenance.BuildingManager;

            if(ModelState.IsValid) {
                var contractor = contractorsRepository.GetById(delegateRepairModel.Contractor);
                if(contractor != null) {
                    try {
                        maintenance.SetContractor(contractor);
                        if (!string.IsNullOrEmpty(delegateRepairModel.Maintenance.Instructions)) {
                            maintenance.Instructions = delegateRepairModel.Maintenance.Instructions;
                        }

                        var url = Url.Action("maintenance", "contractor", new {Id = maintenance.Id}, "http");
                        emailNotifier.NotifyOfMaintenanceDelegation(maintenance, url);
                        return RedirectToAction("details", new { Id = maintenance.Id });

                    } catch (BusinessRulesException ex) {
                        ex.CopyTo(ModelState);
                    }
                } else {
                    ModelState.AddModelError("Contractor", "Niste odabrali izvođača radova.");
                }

            }

            var contractors = contractorsRepository.GetContractorsByRepairService(maintenance.ServiceType, buildingManager);
            delegateRepairModel.Maintenance = Mapper.Map<Maintenance, MaintenanceDetailModel>(maintenance);
            delegateRepairModel.Roles = Roles.GetRolesForUser();
            delegateRepairModel.CurrentRole = "buildingmanager";
            delegateRepairModel.Links = new LinksModel() {
                Id = maintenance.Building.Id,
                Links = NavLinksGenerator.GetManagerLinks(maintenance.Building, "Kvarovi")
            };
            delegateRepairModel.Contractors = Mapper.Map<IList<Contractor>, IList<ContractorModel>>(contractors);

            return View(delegateRepairModel);
        }
        public ActionResult DelegateRepair(int id)
        {
            if(!User.IsInRole("buildingmanager")) { return new HttpUnauthorizedResult(); }

            var maintenance = maintenancesRepository.GetById(id);
            if (maintenance == null) { return HttpNotFound(); }

            BuildingManager buildingManager = maintenance.BuildingManager;
            var contractors = contractorsRepository.GetContractorsByRepairService(maintenance.ServiceType, buildingManager);

            var model = new DelegateRepairModel() {
                Maintenance = Mapper.Map<Maintenance, MaintenanceDetailModel>(maintenance),
                Contractors = Mapper.Map<IList<Contractor>, IList<ContractorModel>>(contractors),
                Roles = Roles.GetRolesForUser(),
                CurrentRole = "buildingmanager",
                Links = new LinksModel() { Id = maintenance.Building.Id, Links = NavLinksGenerator.GetManagerLinks(maintenance.Building, "Kvarovi")}
            };

            return View(model);
        }