/// <summary author="Austin Delaney" created="2019/04/25"> /// Gets a fully populated user specific view of a particular thread from the data store /// by searching for its ID. /// </summary> /// <param name="threadID">The ID of the thread to get data on.</param> /// <param name="user">The user who is viewing the thread.</param> /// <returns>The fully populated thread object representing the requested thread.</returns> public UserThread GetUserThread(int threadID, ISender user) { if (null == user) { throw new ArgumentNullException("A user must be provided that is viewing the thread, cannot be null."); } UserThread result; try { result = dao.GetUserThreadData(threadID, user.Email); } catch (Exception ex) { Exception exc = new Exception("Error occurred retrieving thread " + threadID + " data for user " + user.Email, ex); ExceptionLogManager.getInstance().LogException(exc); throw exc; } //Set the participants of the thread. Dictionary <IMessagable, string> participantsWithAlias = new Dictionary <IMessagable, string>(); //TRY and guess what this does try { //Get all the emails and aliases of the participants first Dictionary <string, string> emailsWithAlias = dao.GetThreadParticipantEmailAndAlias(threadID); //Setup the managers to get the properly formed data objects that those emails represent EmployeeManager employeeManager = new EmployeeManager(); GuestManager guestManager = new GuestManager(); MemberManagerMSSQL memberManager = new MemberManagerMSSQL(); //Heres the tricky part //Using the list of all your emails, get an IEnumerable of all the objects that are found to match those emails //Why is this so ugly? It's not. Your eyes simply can't appreciate it's beauty. IEnumerable <ISender> foundParticipants = new List <ISender>().Concat( employeeManager.SelectAllEmployees().Where(e => emailsWithAlias.Select(kp => kp.Key).Contains(e.Email))).Concat( guestManager.ReadAllGuests().Where(g => emailsWithAlias.Select(kp => kp.Key).Contains(g.Email))).Concat( memberManager.RetrieveAllMembers().Where(m => emailsWithAlias.Select(kp => kp.Key).Contains(m.Email))); //Using the list of objects you obtained, cast those objects to an imessagable and assign them the value that is found for their email foreach (var participantObject in foundParticipants) { participantsWithAlias[participantObject as IMessagable] = emailsWithAlias[participantObject.Email]; } } catch (Exception ex) { Exception exc = new Exception("Error while populating participants for thread " + threadID, ex); ExceptionLogManager.getInstance().LogException(exc); } result.ParticipantsWithAlias = participantsWithAlias; //Set the messages of the thread. IEnumerable <Message> messages = new List <Message>(); //Try to properly retrieve them from data store. If unsuccessful, log exception and set //thread messages to an empty list try { RealMessageManager manager = new RealMessageManager(daoType); messages = manager.RetrieveThreadMessages(new UserThread { ThreadID = threadID }); } catch (Exception ex) { Exception exc = new Exception("Unable to retrieve messages for thread " + threadID, ex); ExceptionLogManager.getInstance().LogException(exc); } result.Messages = messages.ToList(); //Return the (hopeuflly) fully formed UserThread object return(result); }
public ResortVehicleCheckoutDecorator(ResortVehicleManager resortVehicleManager , EmployeeManager employeeManager) { _resortVehicleManager = resortVehicleManager; _employeeManager = employeeManager; }