68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Security.Claims;
|
|||
|
|
using OnlineAssessment.Common;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using OnlineAssessment.Data.EFCore;
|
|||
|
|
using OnlineAssessment.Domain.Models;
|
|||
|
|
using OnlineAssessment.Domain.ViewModels;
|
|||
|
|
|
|||
|
|
namespace OnlineAssessment.V1.Controllers
|
|||
|
|
{
|
|||
|
|
[Authorize]
|
|||
|
|
[ApiVersion("1.0")]
|
|||
|
|
[Route("v{version:apiVersion}/[controller]")]
|
|||
|
|
public class NotificationController : BaseController<UserGroups, EFCoreUserGroupRepository>
|
|||
|
|
{
|
|||
|
|
EFCoreUserGroupRepository _repository;
|
|||
|
|
string responseMessage = string.Empty;
|
|||
|
|
public NotificationController(EFCoreUserGroupRepository repository) : base(repository)
|
|||
|
|
{
|
|||
|
|
_repository = repository;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Attch users to the user group
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[HttpPost("{user_group_id}/Message")]
|
|||
|
|
[Authorize(Roles = "Admin")]
|
|||
|
|
public async System.Threading.Tasks.Task<IActionResult> Message()
|
|||
|
|
{
|
|||
|
|
IActionResult returnResponse;
|
|||
|
|
|
|||
|
|
// The topic name can be optionally prefixed with "/topics/".
|
|||
|
|
var topic = "practiceKea";
|
|||
|
|
|
|||
|
|
// See documentation on defining a message payload.
|
|||
|
|
var message = new FirebaseAdmin.Messaging.Message()
|
|||
|
|
{
|
|||
|
|
Data = new Dictionary<string, string>()
|
|||
|
|
{
|
|||
|
|
{ "score", "850" },
|
|||
|
|
{ "time", "2:45" },
|
|||
|
|
},
|
|||
|
|
Topic = topic,
|
|||
|
|
|
|||
|
|
Notification = new FirebaseAdmin.Messaging.Notification
|
|||
|
|
{
|
|||
|
|
Title = "Message Title",
|
|||
|
|
Body = "Message Body"
|
|||
|
|
},
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// Send a message to the devices subscribed to the provided topic.
|
|||
|
|
string response = await FirebaseAdmin.Messaging.FirebaseMessaging.DefaultInstance.SendAsync(message);
|
|||
|
|
// Response is a message ID string.
|
|||
|
|
Console.WriteLine("Successfully sent message: " + response);
|
|||
|
|
|
|||
|
|
returnResponse = Ok(ReturnResponse.GetSuccessStatus(response));
|
|||
|
|
|
|||
|
|
return returnResponse;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|