Ejemplo n.º 1
0
        public IViewComponentResult Invoke()
        {
            var list = _messageService.GetMessage();

            List <MessageListDto> model = new List <MessageListDto>();

            foreach (var item in list)
            {
                MessageListDto contact = new MessageListDto();
                contact.Id       = item.Id;
                contact.Name     = item.Name;
                contact.Message  = item.Message;
                contact.Email    = item.Email;
                contact.Date     = item.Date;
                contact.ReadInfo = item.ReadInfo;

                model.Add(contact);
            }



            ViewBag.li = model;
            if (model.Count <= 0)
            {
                ViewBag.bos = "Mesaj Bulunamadı";
            }

            return(View());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 消息存储至缓存
        /// </summary>
        /// <returns></returns>
        private async Task <List <MessageListDto> > StoreCacheMessage()
        {
            var messages = await _messageRepository.GetAll().OrderByDescending(c => c.CreationTime).Take(1000).ToListAsync();

            var customers = await _customerRepository.GetAllListAsync();

            var jobs = await _jobRepository.GetAllListAsync();

            var family = await _familyRepository.GetAllListAsync();

            var result = new List <MessageListDto>();

            foreach (var c in messages)
            {
                var model = new MessageListDto()
                {
                    Content        = c.Content,
                    ReceiverId     = c.ReceiverId,
                    ReceiverAvator = c.ReceiverAvator,
                    SenderAvator   = c.SenderAvator,
                    SenderId       = c.SenderId,
                    State          = c.State,
                    Type           = c.Type,
                    CreationTime   = c.CreationTime
                };
                model.SenderName = customers.FirstOrDefault(w => w.Id == model.SenderId)?.Name;

                if (c.Type == MessageType.P2P)
                {
                    model.ReceiverName = customers.FirstOrDefault(w => w.Id == model.ReceiverId)?.Name;
                }
                if (c.Type == MessageType.Job)
                {
                    model.ReceiverName = jobs.FirstOrDefault(w => w.Id == model.ReceiverId)?.Name;
                }
                if (c.Type == MessageType.Group)
                {
                    model.ReceiverName = family.FirstOrDefault(w => w.Id == model.ReceiverId)?.Name;
                }
                result.Add(model);
            }
            return(result);
        }