public async Task <IActionResult> CountMessageNoRead([FromBody] ListIdAccount _list)
        {
            if (_list == null)
            {
                return(BadRequest(new { message = "Request is invalid" }));
            }

            List <int> listCountMessageNoRead = new List <int>();

            foreach (int receiverId in _list.listId)
            {
                var CountMessageNoRead = await _context.Messages
                                         .Join(
                    _context.SenderReceives,
                    mess => mess.message_id,
                    sr => sr.message_id,
                    (mess, sr) => new
                {
                    mess,
                    sr
                }
                    )
                                         .Where(mes => mes.mess.is_read == "0" && mes.sr.sender_id == receiverId && mes.sr.receive_id == _list.senderId)
                                         .CountAsync();

                listCountMessageNoRead.Add(CountMessageNoRead);
            }

            return(Ok(listCountMessageNoRead));
        }
예제 #2
0
        public async Task <IActionResult> GetAccountByListId([FromBody] ListIdAccount listId)
        {
            if (listId == null)
            {
                return(BadRequest(new { message = "Request is invalid" }));
            }

            try
            {
                var listAccount = await _context.Accounts
                                  .Where(acc => listId.listId.Contains(acc.id))
                                  .Select(acc => new
                {
                    id        = acc.id,
                    name      = acc.name,
                    phone     = acc.phone,
                    address   = acc.address,
                    image_url = acc.image_url
                }).ToListAsync();

                return(Ok(listAccount));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }