public List <ProfessionalWorkingHourUiDto> GetUiDto_AllProfessionalWorkingHoursInCompanyFromUserGuid(string userIdString)
        {
            List <ProfessionalWorkingHourUiDto> returnList = new List <ProfessionalWorkingHourUiDto>();
            AuthorizationState authState = AuthorizationState.NotAllowed;
            bool isCompanyOwner          = false;

            // Use AccessQueries to Check if the user has access (currently only the company owner)
            // Get all the professional Id's for the company while we're at it.
            Company company = _accessQueries.GetAuthorization_ForCompanyAdmin_IfCompanyIdSelectedByUserId(Guid.Parse(userIdString), true, out authState, out isCompanyOwner);

            if (company != null && authState > AuthorizationState.NotAllowed && company.Professionals != null && company.Professionals.Any())
            {
                // Get the working hours for each professionalId.
                var proIds = company.Professionals.Select(i => i.ProfessionalId).ToList();
                proIds.Add(company.Owner.ProfessionalId);

                // maybe take the any() check out here?
                var prosWithHours = _unitOfWork.ProfessionalsRepository.Get(i => proIds.Contains(i.ProfessionalId) && i.ProfessionalWorkingHours.Any(), includeProperties: "ProfessionalWorkingHours").ToList();

                // create rows for all the working hours.
                if (prosWithHours != null && prosWithHours.Any())
                {
                    foreach (var professionalRow in prosWithHours)
                    {
                        if (professionalRow.ProfessionalWorkingHours != null && professionalRow.ProfessionalWorkingHours.Any())
                        {
                            foreach (var workingHourRow in professionalRow.ProfessionalWorkingHours.Where(r => !r.IsDeleted))
                            {
                                if (workingHourRow.CompanyLocationGroup == null)
                                {
                                    continue;
                                }

                                ProfessionalWorkingHourUiDto uiRow = _mapper.Map <ProfessionalWorkingHour, ProfessionalWorkingHourUiDto>(workingHourRow);
                                uiRow.CompanyLocationGroupId = workingHourRow.CompanyLocationGroup.CompanyLocationGroupId;
                                uiRow.ProfessionalId         = professionalRow.ProfessionalId;
                                uiRow.ProfessionalName       = professionalRow.GetFullName();
                                returnList.Add(uiRow);
                            }
                        }
                    }

                    returnList = returnList.OrderBy(i => i.ProfessionalName).ToList();
                }
            }

            return(returnList);
        }
Exemple #2
0
        public ProfessionalWorkingHourVm(ProfessionalWorkingHourUiDto professionalWorkingHourUiDto, List <CompanyLocationGroupUiDto> companyLocationGroups)
        {
            ProfessionalWorkingHourUiDto = professionalWorkingHourUiDto;

            if (companyLocationGroups != null)
            {
                companyLocationGroups = companyLocationGroups.OrderBy(i => i.LocationGroupName).ToList();

                List <SelectListItem> sliList = new List <SelectListItem>();
                foreach (var row in companyLocationGroups)
                {
                    SelectListItem itm = new SelectListItem();
                    itm.Text     = row.LocationGroupName;
                    itm.Value    = row.CompanyLocationGroupId.ToString();
                    itm.Selected = (itm.Value == ProfessionalWorkingHourUiDto.CompanyLocationGroupId.ToString());
                    sliList.Add(itm);
                }
                ProfessionalsAccessableCompanyLocationGroups = sliList.AsEnumerable();
            }
        }
        public List <ProfessionalWorkingHourUiDto> GetUiDto_ProfessionalWorkingHoursFromUserGuid(string userIdString)
        {
            Guid userId = GuidHelper.GetGuid(userIdString);
            List <ProfessionalWorkingHourUiDto> returnList = new List <ProfessionalWorkingHourUiDto>();
            // No access query needed, we just get the pro direct.
            Professional professional = _unitOfWork.ProfessionalsRepository.Get(i => i.ProfessionalUserId == userId, includeProperties: "ProfessionalWorkingHours,ProfessionalWorkingHours.CompanyLocationGroup").FirstOrDefault();

            if (professional != null && professional.ProfessionalWorkingHours != null && professional.ProfessionalWorkingHours.Any())
            {
                foreach (var row in professional.ProfessionalWorkingHours.Where(r => !r.IsDeleted))
                {
                    ProfessionalWorkingHourUiDto uiRow = _mapper.Map <ProfessionalWorkingHour, ProfessionalWorkingHourUiDto>(row);
                    uiRow.CompanyLocationGroupId = row.CompanyLocationGroup.CompanyLocationGroupId;
                    uiRow.ProfessionalId         = professional.ProfessionalId;
                    uiRow.ProfessionalName       = professional.GetFullName();
                    returnList.Add(uiRow);
                }
            }

            return(returnList);
        }