Beispiel #1
0
 public void DeleteBuilding(int buildingID)
 {
     try
     {
         BuildingRepository buildingRepo = new BuildingRepository();
         var r = buildingRepo.Get(buildingID);
         buildingRepo.Delete(r);
         GlobalUnitOfWork.Commit();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
        public Building GetBuildingById(int id)
        {
            Building result;

            try
            {
                BuildingRepository buildingRepo = new BuildingRepository();
                result = buildingRepo.Get(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
Beispiel #3
0
        public IActionResult GetReports(int id, [FromBody] ReportDate reportDate)
        {
            var buildingId = new BuildingId(id);
            var building   = BuildingRepository.Get(buildingId);
            var user       = _userSession.User;
            var userRoles  = user.Roles.Where(r => r.BuildingId == buildingId).ToList();

            var reportRepository = ReportRepository(buildingId);

            IEnumerable <Repositories.ReportListItem> reports;

            if (user.CompanyId == building.MainContractor.Id && userRoles.Any(r => r.UserBuildingRole == UserBuildingRole.Admin))
            {
                reports = reportRepository.GetAll(reportDate.Month, reportDate.Year);
            }
            else if (userRoles.Any(r => r.UserBuildingRole == UserBuildingRole.Admin))
            {
                var usersId = _userRepository.GetBuildingWorkers(buildingId, user.CompanyId)
                              .Select(u => u.Id);
                reports = reportRepository.GetFor(reportDate.Month, reportDate.Year, usersId.Select(i => i.Value).ToArray());
            }
            else
            {
                reports = reportRepository.GetFor(reportDate.Month, reportDate.Year, user.Id.Value);
            }

            var companies = _companyRepository.GetContractors(buildingId).ToList();
            var users     = companies.SelectMany(c => _userRepository.GetWorkers(c.Id));

            return(Ok(reports.GroupBy(r => r.Date.Day)
                      .Select(g => new ReportList
            {
                Day = g.Key,
                Reports = g.Select(r =>
                {
                    var us = users.Single(u => u.Id.Value == r.UserId);
                    return new ReportListItem
                    {
                        Id = r.Id,
                        CompanyName =
                            companies.Single(c => c.Id == us.CompanyId).Name,
                        UserName = $"{us.FirstName} {us.LastName} ({us.Email})"
                    };
                })
            }).OrderBy(g => g.Day)));
        }