|
|
@ -1,83 +1,77 @@
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using DataBase.DataManager;
|
|
|
|
|
|
|
|
using DataBase.Entity;
|
|
|
|
|
|
|
|
using DTO;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ApiLeapHit.Controllers
|
|
|
|
namespace ApiLeapHit.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
public class MessageController : Controller
|
|
|
|
public class MessageController : Controller
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// GET: MessageController
|
|
|
|
private readonly DbDataManager _dataManager;
|
|
|
|
public ActionResult Index()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: MessageController/Details/5
|
|
|
|
|
|
|
|
public ActionResult Details(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: MessageController/Create
|
|
|
|
public MessageController(DbDataManager dataManager)
|
|
|
|
public ActionResult Create()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return View();
|
|
|
|
_dataManager = dataManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: MessageController/Create
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
[HttpPost]
|
|
|
|
public async Task<ActionResult<DTOMessage>> ReceiveMessage(int id)
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
|
|
|
public ActionResult Create(IFormCollection collection)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
var message = await _dataManager.ReceiveMessage(id);
|
|
|
|
|
|
|
|
if (message == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: MessageController/Edit/5
|
|
|
|
var player = await _dataManager.GetPlayer(message.player);
|
|
|
|
public ActionResult Edit(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return View();
|
|
|
|
var dtoMessage = new DTOMessage
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
messageId = message.messageId,
|
|
|
|
|
|
|
|
message = message.message,
|
|
|
|
|
|
|
|
timestamp = message.timestamp,
|
|
|
|
|
|
|
|
PlayerId = new DTOPlayer
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
playerId = player.playerId,
|
|
|
|
|
|
|
|
name = player.name,
|
|
|
|
|
|
|
|
nbBallTouchTotal = player.nbBallTouchTotal,
|
|
|
|
|
|
|
|
timePlayed = player.timePlayed
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return Ok(dtoMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: MessageController/Edit/5
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
[HttpPost]
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
public async Task<ActionResult> SendMessage([FromBody] DTOMessage dtoMessage)
|
|
|
|
public ActionResult Edit(int id, IFormCollection collection)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
var player = await _dataManager.GetPlayer(dtoMessage.PlayerId.playerId);
|
|
|
|
{
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
var message = new Message
|
|
|
|
}
|
|
|
|
|
|
|
|
catch
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return View();
|
|
|
|
messageId = dtoMessage.messageId,
|
|
|
|
}
|
|
|
|
message = dtoMessage.message,
|
|
|
|
}
|
|
|
|
timestamp = dtoMessage.timestamp,
|
|
|
|
|
|
|
|
player = player.playerId
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// GET: MessageController/Delete/5
|
|
|
|
await _dataManager.SendMessage(message);
|
|
|
|
public ActionResult Delete(int id)
|
|
|
|
return Ok();
|
|
|
|
{
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: MessageController/Delete/5
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
[HttpPost]
|
|
|
|
public async Task<ActionResult> RemoveMessage(int id)
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
|
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
var result = await _dataManager.RemoveMessage(id);
|
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return View();
|
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NotFound(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|