// Get a conversation by a receiver public ConversationBase ConversationGetByReceiver(int receiverId) { // Get current user's msgs User cUser = GetCurrentUser(); if (cUser == null) { return(null); } // get conversation, ordered by Time var cc = ds.Conversations .Where(c => c.user1 == cUser.UserId | c.user2 == cUser.UserId) .OrderByDescending(c => c.Time); // within current user's conversations, only take the conversation matched with receiverId ConversationBase re = new ConversationBase(); IEnumerable <ConversationBase> cList = Mapper.Map <IEnumerable <ConversationBase> >(cc); foreach (ConversationBase c in cList) { User receiver; if (c.User1 == cUser.UserId && c.User2 == receiverId) { //Get User2 receiver = GetUserByUserID(c.User2); c.UserFirstName = receiver.FirstName; c.UserLastName = receiver.LastName; re = c; } else if (c.User2 == cUser.UserId && c.User1 == receiverId) { //Get User1 receiver = GetUserByUserID(c.User1); c.UserFirstName = receiver.FirstName; c.UserLastName = receiver.LastName; re = c; } //// Get the latest message that talk to receiverId //var msg = ds.Messages // .Where(m => m.SenderId == cUser.UserId || m.ReceiverId == cUser.UserId) // .Where(m => m.SenderId == receiverId || m.ReceiverId == receiverId) // .OrderByDescending(t => t.Time).Take(1); //IEnumerable<MessageBase> recentMsg = Mapper.Map<IEnumerable<MessageBase>>(msg); //foreach (MessageBase message in recentMsg) //{ // re.recentMessage = message; //} } return((re == null) ? null : re); }
public void Start() { Type conversationType = null; switch (Globals.ConversationPerson) { case "Example": conversationType = typeof(ExampleConversation); break; case "Tom": if (!Globals.HadFirstTomConversation) { //conversationType = typeof(TomConvo1); conversationType = typeof(TomConvo1); } else if (!Globals.HadSecondTomConversation) { conversationType = typeof(TomConvo2); } else if (!Globals.HadThirdTomConversation && Globals.HadFirstGangConversation) { conversationType = typeof(TomConvo4); } else { conversationType = typeof(TomConvo3); } break; case "Dick": if (!Globals.HadFirstDickConversation) { conversationType = typeof(DickConvo1); } else if (!Globals.HadSecondDickConversation) { conversationType = typeof(DickWantsAxe); } else if (Globals.axe >= 1) { conversationType = typeof(GiveAxe); } else { conversationType = typeof(Dick); } break; case "Dorothy": if (!Globals.GotAxe) { conversationType = typeof(GetAxe); } else { conversationType = typeof(Dorothy); } break; case "El Pacone": if (!Globals.HadFirstGangConversation) { conversationType = typeof(GangConvo1); } else { conversationType = typeof(GangBlurb1); } break; } ConversationBase conversation = Activator.CreateInstance(conversationType, NPCText, PlayerText1, PlayerText2, Choice1, Choice2, ContinueButton, NPC, TextBox, MoneyPanel, MoneyText) as ConversationBase; conversation.Part1(); }