60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using System.Collections.Generic;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Oqtane.Shared;
|
|
using Oqtane.Enums;
|
|
using Oqtane.Infrastructure;
|
|
using SZUAbsolventenverein.Module.PremiumArea.Services;
|
|
using Oqtane.Controllers;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using Oqtane.Models;
|
|
|
|
namespace SZUAbsolventenverein.Module.PremiumArea.Controllers
|
|
{
|
|
[Route(ControllerRoutes.ApiRoute)]
|
|
public class UserContactController : ModuleControllerBase
|
|
{
|
|
private readonly IUserContactService _service;
|
|
|
|
public UserContactController(IUserContactService service, ILogManager logger, IHttpContextAccessor accessor) : base(logger, accessor)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
// GET: api/<controller>/search/query?moduleid=x
|
|
[HttpGet("search/{query}")]
|
|
[Authorize(Policy = PolicyNames.ViewModule)]
|
|
public async Task<IEnumerable<User>> Search(string query, string moduleid)
|
|
{
|
|
int ModuleId;
|
|
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
|
|
{
|
|
return await _service.SearchUsersAsync(query, ModuleId);
|
|
}
|
|
else
|
|
{
|
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// POST: api/<controller>/send
|
|
[HttpPost("send")]
|
|
[Authorize(Policy = PolicyNames.ViewModule)]
|
|
public async Task Send(int recipientId, string message, string moduleid)
|
|
{
|
|
int ModuleId;
|
|
if (int.TryParse(moduleid, out ModuleId) && IsAuthorizedEntityId(EntityNames.Module, ModuleId))
|
|
{
|
|
await _service.SendMessageAsync(recipientId, message, ModuleId);
|
|
}
|
|
else
|
|
{
|
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
|
}
|
|
}
|
|
}
|
|
}
|