Реализована функция сохранения сообщений, а также просмотр сообщений

This commit is contained in:
EkaterinaR 2024-11-17 00:04:09 +04:00
parent c5eaf380d1
commit 1fdcf756f9
7 changed files with 283 additions and 123 deletions

View File

@ -114,11 +114,20 @@ namespace EventVisitorClientApp.Controllers
Response.Redirect("Index");
}
/// <summary>
/// Ìåòîäû äëÿ îðãàíèçàòîðà
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Register()
{
return View();
}
}
public IActionResult Logout()
{
APIClient.Client = null;
return Redirect("~/Home/Enter");
}
public static string GenerateRandomString()
{
@ -169,6 +178,10 @@ namespace EventVisitorClientApp.Controllers
}
}
/// <summary>
/// Óïðàâëåíèå ìåðîïðèÿòèÿìè
/// </summary>
/// <returns></returns>
public IActionResult MyEvents()
{
if (APIClient.Client == null)
@ -177,7 +190,122 @@ namespace EventVisitorClientApp.Controllers
}
return View(APIClient.GetRequest<List<EventViewModel>>($"api/main/GetEventList?OrganizerId={APIClient.Client.Id}"));
}
public IActionResult CreateEvent()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
public IActionResult ViewEvent(int id)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
return View(eventDetails);
}
[HttpPost]
public void CreateEvent(string name, string description, string type, string phone, string email, string address, string city, string status, int count, DateTime timestart, DateTime timeend)
{
if (APIClient.Client == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
string eventId = Guid.NewGuid().ToString(); // Ãåíåðàöèÿ óíèêàëüíîãî èäåíòèôèêàòîðà äëÿ ìåðîïðèÿòèÿ
string registrationLink = $"https://localhost:7186/registrationonevent?EventId={eventId}"; // Ôîðìèðîâàíèå ññûëêè íà ðåãèñòðàöèþ
APIClient.PostRequest("api/main/createevent", new EventBindingModel
{
Name = name,
Description = description,
Type = type,
ContactPhone = phone,
Address = address,
City = city,
Status = status,
ContactEmail = email,
TimeEnd = timeend.ToUniversalTime(),
TimeStart = timestart.ToUniversalTime(),
Date = DateTime.Now.ToUniversalTime(),
CountVisitors = count,
FreePlaces = count,
OrganizerId = APIClient.Client.Id,
Link = registrationLink
});
Response.Redirect("MyEvents");
}
public IActionResult DeleteEvent(int id)
{
// Ïðîâåðêà íà àâòîðèçàöèþ ïîëüçîâàòåëÿ
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
// Âûïîëíåíèå çàïðîñà íà óäàëåíèå ìåðîïðèÿòèÿ
APIClient.PostRequest($"api/main/DeleteEvent", new EventBindingModel { Id = id });
// Ïåðåíàïðàâëåíèå îáðàòíî íà ñòðàíèöó ñ ìåðîïðèÿòèÿìè
return RedirectToAction("MyEvents");
}
public IActionResult UpdateEvent(int id)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
return View(eventDetails);
}
[HttpPost]
public void UpdateEvent(int id, string name, string description, string type, string phone, string email, string address, string city, string status, int count, DateTime? timestart, DateTime? timeend)
{
if (APIClient.Client == null)
{
throw new Exception("Íåîáõîäèìà àâòîðèçàöèÿ");
}
var existingEvent = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
DateTime start = (timestart.HasValue) ? DateTime.SpecifyKind(timestart.Value, DateTimeKind.Utc) : existingEvent.TimeStart.ToUniversalTime();
DateTime end = (timeend.HasValue) ? DateTime.SpecifyKind(timeend.Value, DateTimeKind.Utc) : existingEvent.TimeEnd.ToUniversalTime();
int countRegisterPlace = existingEvent.CountVisitors - existingEvent.FreePlaces;
APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel
{
Id = id,
Name = name,
Description = description,
Type = type,
ContactPhone = phone,
Address = address,
City = city,
Status = status,
ContactEmail = email,
TimeEnd = end,
TimeStart = start,
Date = DateTime.Now.ToUniversalTime(),
CountVisitors = count,
FreePlaces = count - countRegisterPlace,
OrganizerId = APIClient.Client.Id
});
Response.Redirect("/Home/MyEvents");
}
/// <summary>
/// Óïðàâëåíèå ïîñåòèòåëÿìè
/// </summary>
/// <param></param>
/// <returns></returns>
public IActionResult Visitors(int id)
{
if (APIClient.Client == null)
@ -204,26 +332,6 @@ namespace EventVisitorClientApp.Controllers
}
}
public IActionResult CreateEvent()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
public IActionResult ViewEvent(int id)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
return View(eventDetails);
}
public IActionResult ResultRegistration()
{
return View();
@ -291,117 +399,56 @@ namespace EventVisitorClientApp.Controllers
}
[HttpPost]
public void CreateEvent(string name, string description, string type, string phone, string email, string address, string city, string status, int count, DateTime timestart, DateTime timeend)
{
if (APIClient.Client == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
string eventId = Guid.NewGuid().ToString(); // Ãåíåðàöèÿ óíèêàëüíîãî èäåíòèôèêàòîðà äëÿ ìåðîïðèÿòèÿ
string registrationLink = $"https://localhost:7186/registrationonevent?EventId={eventId}"; // Ôîðìèðîâàíèå ññûëêè íà ðåãèñòðàöèþ
APIClient.PostRequest("api/main/createevent", new EventBindingModel
{
Name = name,
Description = description,
Type = type,
ContactPhone = phone,
Address = address,
City = city,
Status = status,
ContactEmail = email,
TimeEnd = timeend.ToUniversalTime(),
TimeStart = timestart.ToUniversalTime(),
Date = DateTime.Now.ToUniversalTime(),
CountVisitors = count,
FreePlaces = count,
OrganizerId = APIClient.Client.Id,
Link = registrationLink
});
Response.Redirect("MyEvents");
}
public IActionResult DeleteEvent(int id)
{
// Ïðîâåðêà íà àâòîðèçàöèþ ïîëüçîâàòåëÿ
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
// Âûïîëíåíèå çàïðîñà íà óäàëåíèå ìåðîïðèÿòèÿ
APIClient.PostRequest($"api/main/DeleteEvent", new EventBindingModel { Id = id });
// Ïåðåíàïðàâëåíèå îáðàòíî íà ñòðàíèöó ñ ìåðîïðèÿòèÿìè
return RedirectToAction("MyEvents");
}
public IActionResult UpdateEvent(int id)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
return View(eventDetails);
}
public IActionResult SendMessage(int id)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
return View(eventDetails);
}
[HttpPost]
public void UpdateEvent(int id, string name, string description, string type, string phone, string email, string address, string city, string status, int count, DateTime? timestart, DateTime? timeend)
public void ViewEvent(int id, string subject, string message)
{
if (APIClient.Client == null)
{
throw new Exception("Íåîáõîäèìà àâòîðèçàöèÿ");
}
var existingEvent = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
DateTime start = (timestart.HasValue) ? DateTime.SpecifyKind(timestart.Value, DateTimeKind.Utc) : existingEvent.TimeStart.ToUniversalTime();
DateTime end = (timeend.HasValue) ? DateTime.SpecifyKind(timeend.Value, DateTimeKind.Utc) : existingEvent.TimeEnd.ToUniversalTime();
int countRegisterPlace = existingEvent.CountVisitors - existingEvent.FreePlaces;
APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel
var visitorList = APIClient.GetRequest<List<VisitorViewModel>>($"api/main/GetVisitorList?EventId={id}");
if (visitorList != null)
{
Id = id,
Name = name,
Description = description,
Type = type,
ContactPhone = phone,
Address = address,
City = city,
Status = status,
ContactEmail = email,
TimeEnd = end,
TimeStart = start,
Date = DateTime.Now.ToUniversalTime(),
CountVisitors = count,
FreePlaces = count - countRegisterPlace,
OrganizerId = APIClient.Client.Id
foreach (var visitor in visitorList)
{
APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
{
MailAddress = visitor.Email,
Subject = subject,
Text = message
});
}
}
APIClient.PostRequest("api/main/CreateMessage", new SentMessageBindingModel
{
Subject = subject,
Body = message,
EventId = id,
OrganizerId = APIClient.Client.Id,
SentDate = DateTime.Now.ToUniversalTime()
});
Response.Redirect("/Home/MyEvents");
Response.Redirect($"/Home/ViewEvent/{id}");
}
public IActionResult MessageHistory(int id)
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
var allMessages = APIClient.GetRequest<List<SentMessageViewModel>>($"api/main/GetSentMessageList?EventId={id}");
return View(allMessages);
}
/// <summary>
/// Îò÷åòû
/// </summary>
/// <returns></returns>
public IActionResult GetWordFile()
{
return new PhysicalFileResult("F:\\EventVisitor\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
}
public IActionResult Logout()
{
APIClient.Client = null;
return Redirect("~/Home/Enter");
}
public IActionResult GetExcelFile()
{

View File

@ -11,6 +11,7 @@ builder.Services.AddControllersWithViews();
builder.Services.AddTransient<IEventStorage, EventStorage>();
builder.Services.AddTransient<IVisitorStorage, VisitorStorage>();
builder.Services.AddTransient<IOrganizerStorage, OrganizerStorage>();
builder.Services.AddTransient<ISentMessageStorage, SentMessageStorage>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
var app = builder.Build();

View File

@ -0,0 +1,61 @@
@using EventVisitorLogic.ViewModels
@model List<SentMessageViewModel>
@{
ViewData["Title"] = "Отправленные сообщения";
}
<div class="container mt-5">
<div class="text-center">
<h1 class="display-4">Отправленные сообщения</h1>
</div>
<form method="post">
<div class="text-center mt-4">
@{
<table class="table table-striped table-bordered mt-4">
<thead class="thead-light">
<tr>
<th>Дата отправления</th>
<th>Тема</th>
<th>Содержание</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.SentDate)</td>
<td>@Html.DisplayFor(modelItem => item.Subject)</td>
<td>@Html.DisplayFor(modelItem => item.Body)</td>
</tr>
}
</tbody>
</table>
}
</div>
</form>
</div>
<style>
body {
background-color: #f8f9fa;
}
.table {
margin-top: 20px;
}
.btn {
transition: background-color 0.3s ease;
}
.btn-light {
background-color: #e9ecef; /* Светло-серый цвет */
color: #495057; /* Тёмный текст для контраста */
}
.btn-light:hover {
background-color: #d3d3d3; /* Более тёмный светло-серый при наведении */
}
</style>

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace EventVisitorClientApp.Views.Home
{
public class MessageHistoryModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@ -38,16 +38,18 @@
<h2>Сообщение участникам</h2>
</div>
<div class="card-body">
<form id="messageForm">
<form method="post">
<input type="hidden" name="id" value="@Model.Id" />
<div class="form-group">
<label for="subject" style="font-size: 20px;">Тема сообщения</label>
<input type="text" class="form-control" id="subject" placeholder="Введите тему сообщения" required>
<input type="text" class="form-control" id="subject" name="subject" placeholder="Введите тему сообщения" required>
</div>
<div class="form-group">
<label for="message">Текст сообщения</label>
<textarea class="form-control" id="message" rows="10" placeholder="Введите текст сообщения" required></textarea>
<textarea class="form-control" id="message" rows="10" name="message" placeholder="Введите текст сообщения" required></textarea>
</div>
<button type="submit" class="btn btn-black btn-block">Отправить</button>
<button type="submit" class="btn btn-black btn-block" style="margin-bottom: 20px;">Отправить</button>
<a class="btn btn-black btn-block mb-4" asp-action="MessageHistory" asp-route-id="@Model.Id">История отправленных сообщений</a>
</form>
</div>
</div>

View File

@ -12,16 +12,18 @@ namespace EventVisitorRestApi.Controllers
private readonly IOrganizerLogic _organizer;
private readonly IEventLogic _event;
private readonly IVisitorLogic _visitor;
private readonly ISentMessageLogic _message;
private readonly IReportLogic _reportLogic;
private readonly AbstractMailWorker _mailWorker;
public MainController(IOrganizerLogic organizer, IEventLogic events, IVisitorLogic visitor, AbstractMailWorker mailWorker, IReportLogic reportLogic)
public MainController(IOrganizerLogic organizer, IEventLogic events, IVisitorLogic visitor, AbstractMailWorker mailWorker, IReportLogic reportLogic, ISentMessageLogic message)
{
_organizer = organizer;
_event = events;
_visitor = visitor;
_mailWorker = mailWorker;
_reportLogic = reportLogic;
_message = message;
}
/// Мероприятия
[HttpGet]
@ -77,6 +79,39 @@ namespace EventVisitorRestApi.Controllers
}
}
[HttpPost]
public void CreateMessage(SentMessageBindingModel model)
{
try
{
_message.Create(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<SentMessageViewModel>? GetSentMessageList(int eventId)
{
try
{
if (eventId == null)
{
return _message.ReadList(null);
}
return _message.ReadList(new SentMessageBindingModel
{
EventId = eventId
});
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void RegistrationOnEvent(VisitorBindingModel model)
{

View File

@ -26,10 +26,12 @@ builder.Services.AddSwaggerGen(c =>
builder.Services.AddTransient<IEventStorage, EventStorage>();
builder.Services.AddTransient<IVisitorStorage, VisitorStorage>();
builder.Services.AddTransient<IOrganizerStorage, OrganizerStorage>();
builder.Services.AddTransient<ISentMessageStorage, SentMessageStorage>();
builder.Services.AddTransient<IEventLogic, EventLogic>();
builder.Services.AddTransient<IOrganizerLogic, OrganizerLogic>();
builder.Services.AddTransient<IVisitorLogic, VisitorLogic>();
builder.Services.AddTransient<ISentMessageLogic, SentMessageLogic>();
builder.Services.AddTransient<IReportLogic, ReportLogic>();