Esempio n. 1
0
        public Booking UpdateExistingBooking(Booking existingBooking, Booking editBooking)
        {
            try
            {
                if (!HasBookingChanged(editBooking, existingBooking))
                {
                    throw new NoBookingChangesFoundException();
                }

                editBooking.ID    = existingBooking.ID;
                editBooking.Owner = existingBooking.Owner;
                editBooking.PID   = existingBooking.PID;
                editBooking.Room  = db.Rooms.SingleOrDefault(x => x.ID == editBooking.RoomID);

                db.Entry(existingBooking).CurrentValues.SetValues(editBooking);
                db.ExternalAttendees.RemoveRange(db.ExternalAttendees.Where(x => x.BookingID == editBooking.ID));

                if (editBooking.ExternalAttendees != null)
                {
                    editBooking.ExternalAttendees.ToList().ForEach(x => x.BookingID = editBooking.ID);
                    db.ExternalAttendees.AddRange(editBooking.ExternalAttendees);
                }

                db.SaveChanges(editBooking, false);
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, existingBooking, editBooking));
            }
            catch (Exception e)
            {
                _logger.Error($"Unable to edit existing booking: ID {existingBooking.ID}. An error occured: {e.Message}");
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(null, existingBooking, editBooking));
                return(null);
            }


            Booking result = GetById(editBooking.ID);

            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(result, existingBooking, editBooking));

            return(result);
        }
Esempio n. 2
0
        public RoomDTO GetRoomByLocationAndName(int locationId, string roomName)
        {
            try
            {
                RoomDTO roomDTO = new RoomDTO();

                Location location = _locationRepository.GetLocationById(locationId);
                Room     room     = _roomRepository.GetByLocationAndName(location, roomName);

                roomDTO = new RoomDTO()
                {
                    ID       = room.ID,
                    location = new LocationDTO()
                    {
                        ID   = room.Location.ID,
                        Name = room.Location.Name,
                        LocationCredentials = room.Location.LocationCredentials.ToList().Select(l => { return(new LocationCredentialsDTO()
                            {
                                Department = l.Department, Email = l.Email, ID = l.ID, LocationID = l.LocationID, PhoneNumber = l.PhoneNumber
                            }); }).ToList()
                    },
                    RoomName      = room.RoomName,
                    ComputerCount = room.ComputerCount,
                    SeatCount     = room.SeatCount,
                    PhoneCount    = room.PhoneCount,
                    SmartRoom     = room.SmartRoom,
                    Active        = room.Active
                };
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(roomDTO, locationId, roomName));
                return(roomDTO);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get room using room name: " + roomName, ex);
                var result = new RoomDTO();
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(result, locationId, roomName));
                return(result);
            }
        }
Esempio n. 3
0
        private void SendEmailToOwnerForMultiDelete(string fromEmail, List <Booking> ownerBookings)
        {
            try
            {
                string toEmail = _directoryService.GetUser(new User.Pid(ownerBookings[0].PID)).EmailAddress;
                string body    = _emailHelper.GetEmailMarkup("~/Views/EmailTemplates/AdminMultiCancelledBooking.cshtml", ownerBookings);

                if (!string.IsNullOrEmpty(body) && !string.IsNullOrEmpty(toEmail))
                {
                    _emailHelper.SendEmail(fromEmail, toEmail, "Meeting room booking(s) cancellation", body);
                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, fromEmail, ownerBookings));
                }
                else
                {
                    throw new Exception("Body or To-Email is null.");
                }
            }
            catch (Exception ex)
            {
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, fromEmail, ownerBookings));
                _logger.ErrorException("Unable to send admin multiple bookings email.", ex);
            }
        }
Esempio n. 4
0
        public bool Delete(List <Booking> bookings)
        {
            bool succeeded = true;

            foreach (Booking booking in bookings)
            {
                try
                {
                    db.Bookings.Remove(booking);
                }
                catch (Exception e)
                {
                    succeeded = false;
                    _logger.Error($"Unable to delete booking: ID {booking.ID}. An error occured: {e.Message}");
                    break;
                }
            }
            if (succeeded)
            {
                try
                {
                    db.SaveChanges();
                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(true, bookings));
                    return(true);
                }
                catch (Exception)
                {
                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(false, bookings));
                    return(false);
                }
            }
            else
            {
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(false, bookings));
                return(false);
            }
        }
Esempio n. 5
0
        public void EditRoom(Room existingRoom, Room editRoom)
        {
            Location location = _locationRepository.GetLocationById(existingRoom.LocationID);

            if (existingRoom.RoomName != editRoom.RoomName)
            {
                bool isDuplicate = _roomRepository.GetByLocationAndName(location, editRoom.RoomName) != null;

                if (isDuplicate)
                {
                    RoomExistsException exn = new RoomExistsException();

                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(exn, existingRoom, editRoom));

                    throw exn;
                }
            }

            editRoom.LocationID = existingRoom.LocationID;

            _roomRepository.EditRoom(editRoom);
            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, existingRoom, editRoom));
            _logger.Info("Room successfully Edited: " + editRoom.ID);
        }
Esempio n. 6
0
        public List <User> GetBySurname(string surname)
        {
            PrincipalContext sContext = new PrincipalContext(ContextType.Domain);

            _logger.Debug($"Using PrincipalContext: {context.Name} - Server: {context.ConnectedServer}");
            UserPrincipal userPrincipal = new UserPrincipal(sContext);

            _logger.Debug($"Using UserPrincipal: {userPrincipal.Name} - Default");

            userPrincipal.Surname = surname + "*";
            PrincipalSearcher search = new PrincipalSearcher(userPrincipal);
            List <User>       users  = new List <User>();

            PrincipalSearchResult <Principal> searchResults = search.FindAll();

            _logger.Debug($"Principal search executed. Result: Count: {searchResults.Count()}");

            foreach (UserPrincipal result in searchResults)
            {
                if (!string.IsNullOrWhiteSpace(result.SamAccountName) && !string.IsNullOrWhiteSpace(result.EmailAddress) &&
                    (!string.IsNullOrEmpty(result.GivenName) || !string.IsNullOrEmpty(result.Surname)))
                {
                    users.Add(new User()
                    {
                        FirstName    = result.GivenName,
                        LastName     = result.Surname,
                        PayId        = new User.Pid(result.SamAccountName),
                        EmailAddress = result.EmailAddress
                    });
                }
            }

            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(users, surname));

            return(users);
        }
Esempio n. 7
0
        public IEnumerable <BookingDTO> GetBookingsFilterSearch(int?locationId, DateTime?startDate, string room, bool smartRoom)
        {
            string currentPid = User.Identity.Name.Substring(User.Identity.Name.IndexOf("\\") + 1);

            _logger.Debug($"CurrentPID: {currentPid}");

            Location searchLocation = null;

            if (locationId != null && locationId != 0)
            {
                searchLocation = _locationsRepository.GetLocationById(locationId.Value);
            }

            Room searchRoom = null;

            if (room != null)
            {
                searchRoom = _roomsRepository.GetRoomByName(room);
            }

            var bookings = _bookingsRepository.GetByPartialDateRoomSmartLocationAndPid(startDate, DateTime.Now, currentPid, smartRoom, searchRoom, searchLocation);

            List <BookingDTO> bookingsDTO = new List <BookingDTO>();

            bookings.ForEach(x => bookingsDTO.Add(new BookingDTO()
            {
                ID                = x.ID,
                EndDate           = x.EndDate,
                StartDate         = x.StartDate,
                Subject           = x.Subject,
                Owner             = x.Owner,
                IsSmartMeeting    = x.IsSmartMeeting,
                RecurrenceId      = x.RecurrenceId,
                ExternalAttendees = x.ExternalAttendees.Select(y =>
                {
                    return(new ExternalAttendeesDTO()
                    {
                        ID = y.ID,
                        BookingID = y.BookingID,
                        FullName = y.FullName,
                        CompanyName = y.CompanyName,
                        PassRequired = y.PassRequired
                    });
                }),
                Location = new LocationDTO()
                {
                    ID   = x.Room.Location.ID,
                    Name = x.Room.Location.Name,
                    LocationCredentials = x.Room.Location.LocationCredentials.ToList().Select(l => { return(new LocationCredentialsDTO()
                        {
                            Department = l.Department, Email = l.Email, ID = l.ID, LocationID = l.LocationID, PhoneNumber = l.PhoneNumber
                        }); }).ToList()
                },
                Room = new RoomDTO()
                {
                    ID = x.Room.ID, RoomName = x.Room.RoomName, ComputerCount = x.Room.ComputerCount, PhoneCount = x.Room.PhoneCount, SmartRoom = x.Room.SmartRoom
                }
            }));
            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookingsDTO, locationId, startDate, room, smartRoom));
            return(bookingsDTO);
        }
Esempio n. 8
0
        public BookingDTO GetRoomBookingsForBookingId(int bookingId)
        {
            BookingDTO bookingsDTO = new BookingDTO();

            try
            {
                Booking booking = _bookingsRepository.GetById(bookingId);

                bookingsDTO = new BookingDTO()
                {
                    ID                = booking.ID,
                    EndDate           = booking.EndDate,
                    StartDate         = booking.StartDate,
                    Subject           = booking.Subject,
                    Owner             = booking.Owner,
                    NumberOfAttendees = booking.NumberOfAttendees,
                    RecurrenceId      = booking.RecurrenceId,
                    ExternalAttendees = booking.ExternalAttendees.Select(x =>
                    {
                        return(new ExternalAttendeesDTO()
                        {
                            ID = x.ID,
                            BookingID = x.BookingID,
                            FullName = x.FullName,
                            CompanyName = x.CompanyName,
                            PassRequired = x.PassRequired
                        });
                    }),
                    Flipchart      = booking.Flipchart,
                    Projector      = booking.Projector,
                    DssAssist      = booking.DssAssist,
                    PID            = booking.PID,
                    IsSmartMeeting = booking.IsSmartMeeting,
                    Location       = new LocationDTO()
                    {
                        ID   = booking.Room.Location.ID,
                        Name = booking.Room.Location.Name,
                        LocationCredentials = booking.Room.Location.LocationCredentials.ToList().Select(l => { return(new LocationCredentialsDTO()
                            {
                                Department = l.Department, Email = l.Email, ID = l.ID, LocationID = l.LocationID, PhoneNumber = l.PhoneNumber
                            }); }).ToList()
                    },
                    Room = new RoomDTO()
                    {
                        ID            = booking.Room.ID,
                        RoomName      = booking.Room.RoomName,
                        ComputerCount = booking.Room.ComputerCount,
                        PhoneCount    = booking.Room.PhoneCount,
                        SmartRoom     = booking.Room.SmartRoom,
                        SeatCount     = booking.Room.SeatCount
                    }
                };
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookingsDTO, bookingId));
                return(bookingsDTO);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get booking by id :" + bookingId, ex);
            }
            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookingsDTO, bookingId));
            return(bookingsDTO);
        }
Esempio n. 9
0
        public List <BookingDTO> GetRoomBookingsForRoomAndPerson(string location, DateTime start, DateTime end, string room, string person)
        {
            if (location == null || room == null || person == null)
            {
                var bookings = new List <BookingDTO>();
                _logger.Debug($"Location,Room or Person is null. Location:{location == null}, Room:{room == null}, Person:{person == null}");
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookings, location, start, end, room, person));
                return(bookings);
            }


            List <BookingDTO> bookingsDTO = new List <BookingDTO>();

            try
            {
                Room currentRoom = null;
                if (room != null)
                {
                    currentRoom = _roomsRepository.GetRoomByName(room);
                }

                List <Booking> bookings = _bookingsRepository.GetByDateRoomAndOwner(start, end, currentRoom, person);

                bookings.ForEach(x => bookingsDTO.Add(new BookingDTO()
                {
                    ID                = x.ID,
                    EndDate           = x.EndDate,
                    StartDate         = x.StartDate,
                    Owner             = x.Owner,
                    IsSmartMeeting    = x.IsSmartMeeting,
                    RecurrenceId      = x.RecurrenceId,
                    ExternalAttendees = x.ExternalAttendees.Select(y =>
                    {
                        return(new ExternalAttendeesDTO()
                        {
                            ID = y.ID,
                            BookingID = y.BookingID,
                            FullName = y.FullName,
                            CompanyName = y.CompanyName,
                            PassRequired = y.PassRequired
                        });
                    }),
                    Location = new LocationDTO()
                    {
                        ID   = x.Room.Location.ID,
                        Name = x.Room.Location.Name,
                        LocationCredentials = x.Room.Location.LocationCredentials.ToList().Select(l => { return(new LocationCredentialsDTO()
                            {
                                Department = l.Department, Email = l.Email, ID = l.ID, LocationID = l.LocationID, PhoneNumber = l.PhoneNumber
                            }); }).ToList()
                    },
                    Room = new RoomDTO()
                    {
                        ID = x.Room.ID, RoomName = x.Room.RoomName, ComputerCount = x.Room.ComputerCount, PhoneCount = x.Room.PhoneCount, SmartRoom = x.Room.SmartRoom
                    }
                }));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get bookings for room and person: " + location + "/" + room + "/" + person, ex);
            }
            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookingsDTO, location, start, end, room, person));
            return(bookingsDTO);
        }
Esempio n. 10
0
        public List <RoomDTO> GetAvailableRoomsForLocation(string location, DateTime start, bool smartRoom, DateTime end, int numberOfPeople, int existingBookingId)
        {
            List <RoomDTO> rooms = new List <RoomDTO>();

            if (location == null)
            {
                List <RoomDTO> result = new List <RoomDTO>();
                _logger.Debug("Location is null");
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(result, location, start, smartRoom, end, numberOfPeople, existingBookingId));
                return(result);
            }

            List <Room> roomData = new List <Room>();

            try
            {
                List <Room> availableRooms = new List <Room>();

                Booking existingBooking = _bookingRepository.GetById(existingBookingId);

                List <Booking> clashedBookings;
                existingBooking.StartDate = start;
                existingBooking.EndDate   = end;

                bool meetingClash = _availabilityService.DoesMeetingClash(existingBooking, out clashedBookings);

                if (meetingClash && clashedBookings.Count == 1 && clashedBookings[0].ID == existingBooking.ID)
                {
                    availableRooms.Add(existingBooking.Room);
                }

                else
                {
                    availableRooms = db.Rooms.Where(x => x.Location.Name == location && x.SeatCount >= numberOfPeople && x.Active == true && x.SmartRoom == smartRoom &&
                                                    (x.Bookings.Where(b => start <b.EndDate && end> b.StartDate && b.ID != existingBookingId).Count() == 0)) //Do any bookings overlap
                                     .OrderBy(r => r.SeatCount)
                                     .ToList();
                }
                roomData.AddRange(availableRooms);

                roomData.ForEach(x => rooms.Add(new RoomDTO()
                {
                    ID            = x.ID,
                    RoomName      = x.RoomName,
                    PhoneCount    = x.PhoneCount,
                    ComputerCount = x.ComputerCount,
                    SeatCount     = x.SeatCount,
                    SmartRoom     = x.SmartRoom,
                    Bookings      = x.Bookings.Where(b => b.StartDate.Date == start.Date && b.EndDate.Date == end.Date).Select(b =>
                    {
                        BookingDTO bDto = new BookingDTO()
                        {
                            ID             = b.ID,
                            Owner          = b.Owner,
                            StartDate      = b.StartDate,
                            EndDate        = b.EndDate,
                            IsSmartMeeting = b.IsSmartMeeting
                        };
                        return(bDto);
                    }).ToList()
                }));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get available rooms for location: " + location, ex);
            }
            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(rooms, location, start, smartRoom, end, numberOfPeople, existingBookingId));
            return(rooms);
        }
Esempio n. 11
0
        public List <Booking> GetAvailableSmartRoomBookings(Booking newBooking, out List <Booking> clashedBookings)
        {
            List <Booking> bookingsToCreate = new List <Booking>();
            List <Booking> clashedBs        = new List <Booking>();
            List <int>     smartRoomIds     = new List <int>();

            smartRoomIds.Add(newBooking.RoomID);

            AvailabilityService aC = new AvailabilityService(this, _roomRepository, _locationRepository);

            foreach (var smartLoc in newBooking.SmartLoactions)
            {
                int smartLocId = 0;
                int.TryParse(smartLoc, out smartLocId);

                Room smartLocData = db.Rooms.Where(x => x.ID == smartLocId).Select(x => x).ToList().FirstOrDefault();

                List <Booking> doesClash;
                Room           roomToBook = null;
                if (aC.DoesMeetingClash(new Booking()
                {
                    StartDate = newBooking.StartDate, EndDate = newBooking.EndDate, RoomID = smartLocData.ID
                }, out doesClash))
                {
                    roomToBook = aC.GetAlternateSmartRoom(smartRoomIds, newBooking.StartDate, newBooking.EndDate, db.Locations.Single(l => l.Name == smartLocData.Location.Name).ID);
                }
                else
                {
                    roomToBook = smartLocData;
                }

                if (roomToBook == null || bookingsToCreate.Select(x => x.Room).Contains(roomToBook))
                {
                    clashedBs.Add(new Booking()
                    {
                        StartDate      = newBooking.StartDate,
                        Owner          = newBooking.Owner,
                        IsSmartMeeting = true,
                        Room           = smartLocData
                    });
                }
                else
                {
                    bookingsToCreate.Add(new Booking()
                    {
                        DssAssist         = newBooking.DssAssist,
                        ExternalAttendees = newBooking.ExternalAttendees,
                        Flipchart         = newBooking.Flipchart,
                        NumberOfAttendees = newBooking.Room.SeatCount,
                        Owner             = newBooking.Owner,
                        PID            = newBooking.PID,
                        Projector      = newBooking.Projector,
                        RoomID         = roomToBook.ID,
                        Room           = roomToBook,
                        Subject        = newBooking.Subject,
                        StartDate      = newBooking.StartDate,
                        EndDate        = newBooking.EndDate,
                        IsSmartMeeting = true
                    });

                    smartRoomIds.Add(roomToBook.ID);
                }
            }

            clashedBookings = clashedBs;

            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookingsToCreate, clashedBookings));

            return(bookingsToCreate);
        }
Esempio n. 12
0
        public List <Booking> UpdateExistingBookings(List <Booking> existingBookings, List <Booking> editBookings)
        {
            bool           succeeded      = true;
            List <Booking> bookingsToSave = new List <Booking>();

            foreach (Booking editBooking in editBookings)
            {
                Booking existingBooking = existingBookings.Where(x => x.ID == editBooking.ID).First();
                try
                {
                    editBooking.ID    = existingBooking.ID;
                    editBooking.Owner = existingBooking.Owner;
                    editBooking.PID   = existingBooking.PID;
                    editBooking.Room  = db.Rooms.SingleOrDefault(x => x.ID == editBooking.RoomID);

                    db.Entry(existingBooking).CurrentValues.SetValues(editBooking);
                    db.ExternalAttendees.RemoveRange(db.ExternalAttendees.Where(x => x.BookingID == editBooking.ID));

                    if (editBooking.ExternalAttendees != null)
                    {
                        editBooking.ExternalAttendees.ToList().ForEach(x => x.BookingID = editBooking.ID);
                        db.ExternalAttendees.AddRange(editBooking.ExternalAttendees);
                    }
                    bookingsToSave.Add(editBooking);
                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(LoggerHelper.VOID_TYPE, existingBookings, editBookings));
                }
                catch (Exception e)
                {
                    succeeded = false;
                    _logger.Error($"Unable to delete booking(s): {String.Join(", ", editBookings.Select(x => x.ID))}. An error occured: {e.Message}");
                    break;
                }
            }
            if (succeeded)
            {
                try
                {
                    db.SaveChanges(bookingsToSave, false);
                    List <int> editBookingIds = editBookings.Select(x => x.ID).ToList();

                    List <Booking> bookings = db.Bookings.Where(x => editBookingIds.Contains(x.ID)).ToList();

                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(bookings, existingBookings, editBookings));

                    return(bookings);
                }
                catch (BookingConflictException ex)
                {
                    _logger.Error($"Unable to edit existing booking(s): {String.Join(", ", editBookings.Select(x => x.ID))}. An error occured: {ex.Message}");
                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(ex, existingBookings, editBookings));
                    throw ex;
                }
                catch (Exception ex)
                {
                    _logger.Error($"Unable to edit existing booking(s): {String.Join(", ", editBookings.Select(x => x.ID))}. An error occured: {ex.Message}");
                    _logger.Trace(LoggerHelper.ExecutedFunctionMessage(null, existingBookings, editBookings));
                    return(null);
                }
            }
            else
            {
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(null, existingBookings, editBookings));
                return(null);
            }
        }
Esempio n. 13
0
        public List <RoomDTO> GetRoomsByLocationAndStatus(string locationName, int status)
        {
            try
            {
                Location location = _locationRepository.GetLocationByName(locationName);

                List <RoomDTO> roomDTOs = new List <RoomDTO>();
                List <Room>    rooms    = new List <Room>();

                if (locationName == "location")
                {
                    _logger.Debug("LocationName is \"location\"");
                }

                if (status < 0)
                {
                    if (locationName == "location")
                    {
                        rooms = _roomRepository.GetAllRooms().OrderBy(r => r.Location.Name).ThenBy(r => r.RoomName).ToList();
                    }
                    else
                    {
                        rooms = _roomRepository.GetByLocationName(locationName).OrderBy(r => r.Location.Name).ThenBy(r => r.RoomName).ToList();
                    }
                }
                else
                {
                    bool active = (status == 0) ? false : true;

                    if (locationName == "location")
                    {
                        rooms = _roomRepository.GetByStatus(active).OrderBy(r => r.Location.Name).ThenBy(r => r.RoomName).ToList();
                    }
                    else
                    {
                        rooms = _roomRepository.GetByLocationAndStatus(location, active).OrderBy(r => r.Location.Name).ThenBy(r => r.RoomName).ToList();
                    }
                }

                rooms.ForEach(x => roomDTOs.Add(new RoomDTO()
                {
                    ID       = x.ID,
                    location = new LocationDTO()
                    {
                        ID   = x.Location.ID,
                        Name = x.Location.Name,
                        LocationCredentials = x.Location.LocationCredentials.ToList().Select(l => { return(new LocationCredentialsDTO()
                            {
                                Department = l.Department, Email = l.Email, ID = l.ID, LocationID = l.LocationID, PhoneNumber = l.PhoneNumber
                            }); }).ToList()
                    },
                    RoomName      = x.RoomName,
                    ComputerCount = x.ComputerCount,
                    SeatCount     = x.SeatCount,
                    PhoneCount    = x.PhoneCount,
                    SmartRoom     = x.SmartRoom,
                    Active        = x.Active
                }));
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(roomDTOs, locationName, status));
                return(roomDTOs);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get rooms.", ex);
                var results = new List <RoomDTO>();
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(results, locationName, status));
                return(results);
            }
        }
Esempio n. 14
0
        public User GetCurrentUser(string identity)
        {
            PrincipalContext sContext = new PrincipalContext(ContextType.Domain);

            _logger.Debug($"Using PrincipalContext: {context.Name} - Server: {context.ConnectedServer}");

            if (identity == null)
            {
                _logger.Error($"Identity is null");
                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(null, identity));
                return(null);
            }

            //Remove the domain string
            string pid = identity.Substring(identity.IndexOf("\\") + 1);

            _logger.Debug($"Searching by identity of: Pid-{pid}");
            UserPrincipal result = UserPrincipal.FindByIdentity(sContext, IdentityType.SamAccountName, pid);

            if (!string.IsNullOrWhiteSpace(result.SamAccountName) && !string.IsNullOrWhiteSpace(result.EmailAddress) &&
                (!string.IsNullOrEmpty(result.GivenName) || !string.IsNullOrEmpty(result.Surname)))
            {
                User currentUser = new User()
                {
                    FirstName    = result.GivenName,
                    LastName     = result.Surname,
                    PayId        = new User.Pid(result.SamAccountName),
                    EmailAddress = result.EmailAddress
                };

                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(currentUser, identity));

                return(currentUser);
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();

                if (!string.IsNullOrWhiteSpace(result.SamAccountName))
                {
                    stringBuilder.Append($"SamAccountName value: {result.SamAccountName}, ");
                }
                if (!string.IsNullOrWhiteSpace(result.EmailAddress))
                {
                    stringBuilder.Append($"EmailAddress value: {result.EmailAddress}, ");
                }
                if (!string.IsNullOrEmpty(result.GivenName))
                {
                    stringBuilder.Append($"GivenName value: {result.GivenName}, ");
                }
                if (!string.IsNullOrEmpty(result.Surname))
                {
                    stringBuilder.Append($"Surname value: {result.Surname} ");
                }

                _logger.Error($"Value is missing: {stringBuilder.ToString()}");

                _logger.Trace(LoggerHelper.ExecutedFunctionMessage(null, identity));
                return(null);
            }
        }
Esempio n. 15
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
                            };
                            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(rDto, status, extraInfo));
                            return(rDto);
                        }).ToList()
                    }));
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Unable to get list of locations", ex);
            }
            _logger.Trace(LoggerHelper.ExecutedFunctionMessage(locationsDTO, status, extraInfo));
            return(locationsDTO);
        }