Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            var user = await this.userManager.FindByNameAsync(this.User.Identity.Name);

            var conversations = await this.conversationService.GetUserConversations(user.Id);

            var model = new ConversationIndexViewModel();

            foreach (var conversation in conversations)
            {
                var conversationWith = string.Empty;

                if (conversation.Ad.ApplicationUser.UserName == user.UserName)
                {
                    conversationWith = conversation.Messages.FirstOrDefault(m => m.UserName != user.UserName).UserName;
                }
                else
                {
                    conversationWith = conversation.Ad.ApplicationUser.UserName;
                }

                model.Conversations.Add(new ConversationViewModel
                {
                    Id = conversation.Id,
                    ConversationName = $"{conversationWith} | {conversation.Ad.Title}"
                });
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public IActionResult Index()
        {
            int UserId = ActiveUser.Instance.User.UserId;
            List <Conversation> UserConversations = context.Conversation.Where(c => c.ConversationRecieverId == UserId || c.ConversationStarterId == UserId).ToList();

            UserConversations.ForEach(us => us.ConversationMessages = context.Message.Where(m => us.ConversationRoomName == m.ConversationRoomName).OrderByDescending(m => m.MessageSentDate).Take(1).ToList());

            ConversationIndexViewModel model = new ConversationIndexViewModel(context);

            model.UserStyle     = context.Style.Where(s => s.UserId == UserId).SingleOrDefault();
            model.Conversations = UserConversations.Where(uc => uc.ConversationMessages.Count != 0).ToList();
            model.Conversations = model.Conversations.OrderByDescending(uc => uc.ConversationMessages[0].MessageSentDate).ToList();

            return(View(model));
        }
        public async Task <IActionResult> ConversationByAdIdAndContactId(int adId, string contactId)
        {
            ConversationIndexViewModel model = new ConversationIndexViewModel();
            string userId = _userManager.GetUserId(User);

            model.Conversation = await _conversationService.GetConversationByAdIdAndSenderIdAndContactId(adId, userId, contactId);

            ViewBag.SenderId  = userId;
            ViewBag.RecivedId = contactId;
            ViewBag.AdId      = adId;

            var getAdByIdResult = await _adService.GetAdById(adId, dataForEdit : false);

            if (!getAdByIdResult.Succedeed)
            {
                return(View("Conversations", model));
            }

            model.Ad = getAdByIdResult.Property;
            return(View("Conversations", model));
        }