public ActionResult Index() { var person = personsRepository.GetPersonByUsername(User.Identity.Name); var model = new Models.Dashboard.IndexModel() { Roles = Roles.GetRolesForUser() }; if (User.IsInRole("contractor")) { var maintenances = maintenancesRepository.GetAllMaintenancesByContractor(person as LegalPerson, 5); model.Maintenances = Mapper.Map<IList<Maintenance>, IList<MaintenanceDetailModel>>(maintenances); } if(User.IsInRole("owner")) { var partitionSpaces = partitionSpacesRepository.GetPartitionSpaces(person, 5); var apartments = new List<ApartmentListModel>(); foreach (var partitionSpace in partitionSpaces) { var building = buildingsRepository.GetByPartitionSpace(partitionSpace); var apartment = new ApartmentListModel { PartitionSpace = Mapper.Map<IPartitionSpace, PartitionSpaceListModel>(partitionSpace), Building = Mapper.Map<Building, BuildingListModel>(building) }; apartments.Add(apartment); } model.Apartments = apartments; } if(User.IsInRole("representative")) { IList<Building> representativeBuildings = buildingsRepository.GetBuildingsByRepresentative(person, 5); var representativeBuildingListModel = Mapper.Map<IList<Building>, IList<BuildingListModel>>(representativeBuildings); model.RepresentativeBuildings = representativeBuildingListModel; } if(User.IsInRole("buildingmanager")) { IList<Building> managerBuildings = buildingsRepository.GetBuildingsByManager(person as LegalPerson, 5); var representativeBuildingListModel = Mapper.Map<IList<Building>, IList<BuildingListModel>>(managerBuildings); model.ManagerBuildings = representativeBuildingListModel; } return View(model); }
public ActionResult Index() { if (!User.IsInRole("owner")) { return new HttpUnauthorizedResult(); } var owner = personsRepository.GetPersonByUsername(User.Identity.Name); var partitionSpaces = partitionSpacesRepository.GetPartitionSpaces(owner); var apartments = new List<ApartmentListModel>(); foreach (var partitionSpace in partitionSpaces) { var building = buildingsRepository.GetByPartitionSpace(partitionSpace); var apartment = new ApartmentListModel { PartitionSpace = Mapper.Map<IPartitionSpace, PartitionSpaceListModel>(partitionSpace), Building = Mapper.Map<Building, BuildingListModel>(building) }; apartments.Add(apartment); } var model = new IndexModel() { Apartments = apartments, Roles = Roles.GetRolesForUser() }; return View(model); }