Beispiel #1
0
        //public IActionResult GetToCurrentUser(int page, int countPerPage)
        //{
        //    try
        //    {
        //        string userId = GetCurrentUserId();
        //        List<Broadcast> records = _broadcastsMethods.GetToUser(userId, page, countPerPage, out int totalCount);
        //        return Ok(new
        //        {
        //            records,
        //            totalCount
        //        });
        //    }
        //    catch (ClientException ex)
        //    {
        //        return BadRequest(new { message = ex.Message });
        //    }
        //    catch (Exception ex)
        //    {
        //        return StatusCode(500, new { message = ex.Message });
        //    }
        //}

        // try moving to notifications controller...
        // and also the send to sendbroadcast method
        // for furthur notice

        public async Task <IActionResult> Send([FromBody] SendBroadcastObject model)
        {
            try
            {
                List <Broadcast> sent = new List <Broadcast>();

                string fromUser = User.FindFirst(ClaimTypes.NameIdentifier).Value;

                Broadcast notification = await _broadcastsMethods.Send(fromUser, model.toTeamId, model.message, model.type, true);

                sent.Add(notification);

                //await _notificationsHub.Clients.User("a18be9c0-aa65-4af8-bd17-00bd9344e579").SendAsync("ReceiveBroadcast", notification);
                //await _notificationsHub.Clients.All.SendAsync("ReceiveBroadcast", notification);
                //await _notificationsHub.Clients..All.SendAsync("ReceiveNotification", notification );

                return(Ok(sent));
            }
            catch (ClientException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new { message = ex.Message }));
            }
        }
        public async Task <Broadcast> SendToTeam([FromBody] SendBroadcastObject model)
        {
            string userId = GetCurrentUserId();

            Broadcast notification = await _notificationMethods.SendToTeam(userId, model.toTeamId, model.message, model.type, true);

            return(notification);
        }