|
|
|
@ -1,83 +1,50 @@
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using DataBase.DataManager;
|
|
|
|
|
using DataBase.Entity;
|
|
|
|
|
using DTO;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ApiLeapHit.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ChatController : Controller
|
|
|
|
|
{
|
|
|
|
|
// GET: ChatController
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChatController/Details/5
|
|
|
|
|
public ActionResult Details(int id)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
private readonly DbDataManager _dataManager;
|
|
|
|
|
|
|
|
|
|
// GET: ChatController/Create
|
|
|
|
|
public ActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChatController/Create
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Create(IFormCollection collection)
|
|
|
|
|
public ChatController(DbDataManager dataManager)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
_dataManager = dataManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: ChatController/Edit/5
|
|
|
|
|
public ActionResult Edit(int id)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChatController/Edit/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Edit(int id, IFormCollection collection)
|
|
|
|
|
public async Task<ActionResult> AddChat([FromBody] DTOChat dtoChat)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
var player1 = await _dataManager.GetPlayer(dtoChat.PlayerId2.playerId);
|
|
|
|
|
var player2 = await _dataManager.GetPlayer(dtoChat.PlayerId2.playerId);
|
|
|
|
|
|
|
|
|
|
var chat = new Chat
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
chatId = dtoChat.chatId,
|
|
|
|
|
player1 = player1.playerId,
|
|
|
|
|
player2 = player2.playerId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// GET: ChatController/Delete/5
|
|
|
|
|
public ActionResult Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
await _dataManager.AddChat(chat);
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: ChatController/Delete/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public ActionResult Delete(int id, IFormCollection collection)
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public async Task<ActionResult> RemoveChat(int id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
var result = await _dataManager.RemoveChat(id);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
return NotFound(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|