Example #1
0
        public List <LocationDTO> GetLocations()
        {
            List <LocationDTO> locationsDTO = new List <LocationDTO>();

            try
            {
                List <Location> locations = _locationRepository.GetAllLocations();

                locations.ForEach(x => locationsDTO.Add(new LocationDTO()
                {
                    ID     = x.ID,
                    Name   = x.Name,
                    Active = x.Active,
                    AdditionalInformation = x.AdditionalInformation,
                    LocationCredentials   = x.LocationCredentials.Select(lc =>
                    {
                        LocationCredentialsDTO lcDto = new LocationCredentialsDTO()
                        {
                            ID          = lc.ID,
                            Department  = lc.Department,
                            LocationID  = x.ID,
                            Email       = lc.Email,
                            PhoneNumber = lc.PhoneNumber,
                        }; return(lcDto);
                    }).ToList(),
                    Rooms = x.Rooms.Select(r =>
                    {
                        RoomDTO rDto = new RoomDTO()
                        {
                            ID            = r.ID,
                            RoomName      = r.RoomName,
                            ComputerCount = r.ComputerCount,
                            PhoneCount    = r.PhoneCount,
                            SmartRoom     = r.SmartRoom,
                            SeatCount     = r.SeatCount,
                            Active        = r.Active
                        }; return(rDto);
                    }).ToList()
                }));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get list of locations: ", ex);
            }
            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(locationsDTO));
            return(locationsDTO);
        }
Example #2
0
 public LocationDTO GetLocationById(int id)
 {
     try
     {
         Location    location    = _locationRepository.GetLocationById(id);
         LocationDTO locationDto = new LocationDTO()
         {
             Active = location.Active,
             ID     = location.ID,
             Name   = location.Name,
             AdditionalInformation = location.AdditionalInformation,
             Rooms = location.Rooms.Select(r =>
             {
                 RoomDTO rDto = new RoomDTO()
                 {
                     ID            = r.ID,
                     RoomName      = r.RoomName,
                     ComputerCount = r.ComputerCount,
                     PhoneCount    = r.PhoneCount,
                     SmartRoom     = r.SmartRoom,
                     SeatCount     = r.SeatCount
                 }; return(rDto);
             }).ToList(),
             LocationCredentials = location.LocationCredentials.Select(l =>
             {
                 LocationCredentialsDTO lcDto = new LocationCredentialsDTO()
                 {
                     Department  = l.Department,
                     Email       = l.Email,
                     ID          = location.ID,
                     LocationID  = l.LocationID,
                     PhoneNumber = l.PhoneNumber
                 }; return(lcDto);
             }).ToList()
         };
         _logger.Trace(LoggerHelper.ExecutedFunctionMessage(locationDto, id));
         return(locationDto);
     }
     catch (Exception ex)
     {
         _logger.ErrorException("Unable to get a location by id: " + id, ex);
         var result = new LocationDTO();
         _logger.Trace(LoggerHelper.ExecutedFunctionMessage(result, id));
         return(result);
     }
 }
Example #3
0
        public List <LocationDTO> GetLocationsByStatus(bool status, bool extraInfo)
        {
            List <LocationDTO> locationsDTO = new List <LocationDTO>();

            try
            {
                List <Location> locations = _locationRepository.GetLocationsByStatus(status);

                if (extraInfo)
                {
                    locations.ForEach(x => locationsDTO.Add(new LocationDTO()
                    {
                        ID     = x.ID,
                        Name   = x.Name,
                        Active = x.Active,
                        AdditionalInformation = x.AdditionalInformation,
                        LocationCredentials   = x.LocationCredentials.Select(lc =>
                        {
                            LocationCredentialsDTO lcDto = new LocationCredentialsDTO()
                            {
                                ID          = lc.ID,
                                Department  = lc.Department,
                                LocationID  = x.ID,
                                Email       = lc.Email,
                                PhoneNumber = lc.PhoneNumber,
                            }; return(lcDto);
                        }).ToList(),
                        Rooms = x.Rooms.Select(r =>
                        {
                            RoomDTO rDto = new RoomDTO()
                            {
                                ID            = r.ID,
                                RoomName      = r.RoomName,
                                ComputerCount = r.ComputerCount,
                                PhoneCount    = r.PhoneCount,
                                SmartRoom     = r.SmartRoom,
                                SeatCount     = r.SeatCount,
                                Active        = r.Active
                            }; return(rDto);
                        }).ToList()
                    }));
                }
                else
                {
                    locations.ForEach(x => locationsDTO.Add(new LocationDTO()
                    {
                        ID     = x.ID,
                        Name   = x.Name,
                        Active = x.Active,
                        //Only get smart rooms as we need them for SMART bookings.
                        Rooms = x.Rooms.Where(y => y.SmartRoom == true && y.Active == true).Select(r =>
                        {
                            RoomDTO rDto = new RoomDTO()
                            {
                                ID            = r.ID,
                                RoomName      = r.RoomName,
                                ComputerCount = r.ComputerCount,
                                PhoneCount    = r.PhoneCount,
                                SmartRoom     = r.SmartRoom,
                                SeatCount     = r.SeatCount,
                                Active        = r.Active
                            }; return(rDto);
                        }).ToList()
                    }));
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get list of locations", ex);
            }

            return(locationsDTO);
        }