работает регистрация на мероприятие

This commit is contained in:
EkaterinaR 2024-11-05 14:09:00 +04:00
parent 90a9857425
commit 2539ec26b5
11 changed files with 167 additions and 53 deletions

View File

@ -185,6 +185,35 @@ namespace EventVisitorClientApp.Controllers
return View(eventDetails);
}
public IActionResult RegistrationOnEvent(int id)
{
var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
return View(eventDetails);
}
[HttpPost]
public void RegistrationOnEvent(int id, string name, string phone, string email, DateTime dayBirth)
{
APIClient.PostRequest("api/main/registrationonevent", new VisitorBindingModel
{
Name = name,
Phone = phone,
Email = email,
DayBirth = dayBirth.ToUniversalTime(),
EventId = id,
Status = "Çàðåãèñòèðîâàí"
});
Response.Redirect("ResultRegistration");
}
[HttpGet]
public IActionResult ResultRegistration()
{
return View();
}
[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)
{
@ -192,6 +221,10 @@ namespace EventVisitorClientApp.Controllers
{
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,
@ -208,7 +241,7 @@ namespace EventVisitorClientApp.Controllers
CountVisitors = count,
FreePlaces = count,
OrganizerId = APIClient.Client.Id,
Link = "Îòñóòñòâóåò"
Link = registrationLink
});
Response.Redirect("MyEvents");
}
@ -239,17 +272,6 @@ namespace EventVisitorClientApp.Controllers
return View(eventDetails);
}
//public IActionResult GenerateLink(EventViewModel model, int id)
//{
// if (APIClient.Client == null)
// {
// return Redirect("~/Home/Enter");
// }
// var eventDetails = APIClient.GetRequest<EventViewModel>($"api/main/GetEvent?EventId={id}");
// var registrationLink = Url.Action("Register", "Events", eventid = id, Request.Scheme);
// 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)

View File

@ -96,3 +96,4 @@
</div>
</div>
</form>
</div>

View File

@ -1,13 +1,44 @@
@{
@using EventVisitorLogic.ViewModels
@model EventViewModel
@{
ViewData["Title"] = "RegistrationOnEvent";
}
<div class="containerenter text-center mt-5">
<div class="container mt-5">
<div class="row">
<div class="col-md-6">
<div class="card" style="margin: 10px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); border-radius: 10px;">
<div class="card-header bg-secondary text-light">
<h2>@Html.DisplayFor(model => model.Name)</h2>
</div>
<div class="card-body">
<h4>Описание:</h4>
<p>@Html.DisplayFor(model => model.Description)</p>
<h4>Дата начала:</h4>
<p>@Html.DisplayFor(model => model.TimeStart)</p>
<h4>Дата окончания:</h4>
<p>@Html.DisplayFor(model => model.TimeEnd)</p>
<h4>Статус:</h4>
<p>@Html.DisplayFor(model => model.Status)</p>
<h4>Город:</h4>
<p>@Html.DisplayFor(model => model.City)</p>
<h4>Адрес:</h4>
<p>@Html.DisplayFor(model => model.Address)</p>
<h4>Всего мест:</h4>
<p>@Html.DisplayFor(model => model.CountVisitors)</p>
<h4>Свободных мест:</h4>
<p>@Html.DisplayFor(model => model.FreePlaces)</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="containerenter text-center">
<h2 class="display-4 mb-4">Регистрация на мероприятие</h2>
<form method="post" class="border p-4 rounded">
<div class="mb-4">
<label for="InputName" class="form-label" style="font-size: 24px" ;>Введите имя</label>
<label for="InputName" class="form-label" style="font-size: 24px;">Введите имя</label>
<input type="text" name="name" class="form-control" id="name" required>
<div class="invalid-feedback">Пожалуйста, введите имя.</div>
</div>
@ -34,7 +65,11 @@
<button type="submit" class="btn btn-dark btn-lg w-100">Зарегистрироваться</button>
</div>
</form>
</div>
</div>
</div>
</div>
<style>
.containerenter {
max-width: 500px;
@ -44,11 +79,3 @@
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
</style>

View File

@ -0,0 +1,39 @@
@{
ViewData["Title"] = "Успешная регистрация";
}
<div class="container enter mt-5">
<div class="row">
<div class="col-md-12">
<div class="card h-90">
<div class="card-header bg-secondary text-light">
<h2>Успешная регистрация</h2>
</div>
<div class="card-body">
<p>Вы успешно зарегистрированы на мероприятие. Проверьте почту, мы отправили вам всю информацию туда.</p>
<p>Спасибо за регистрацию!</p>
</div>
</div>
</div>
</div>
</div>
<style>
body {
background-color: #f8f9fa;
}
.card {
margin-top: 20px;
padding: 20px;
}
.btn-black {
background-color: black; /* Цвет кнопки */
color: white; /* Цвет текста кнопки */
}
.btn-block {
width: 100%; /* Широкая кнопка */
}
</style>

View File

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

View File

@ -51,7 +51,7 @@
</form>
</div>
</div>
<button type="submit" class="btn btn-black btn-block mb-4" asp-action="GenerateLink" asp-route-id="@Html.DisplayFor(model => model.Id)">Сгенерировать ссылку для регистрации</button>
<a class="btn btn-dark btn-block mb-4" asp-action="RegistrationOnEvent" asp-route-id="@Model.Id">Страница с регистрацией</a>
<button type="submit" class="btn btn-black btn-block">Зарегистрованные пользователи</button>
</div>
</div>

View File

@ -32,7 +32,7 @@ namespace EventVisitorDatabase.Entities
}
return new VisitorEntity()
{
Id = (int)model.Id,
Id = model.Id,
Name = model.Name,
Phone = model.Phone,
Email = model.Email,

View File

@ -29,14 +29,14 @@ namespace EventVisitorDatabase.Implements
public VisitorViewModel? GetElement(VisitorBindingModel model)
{
if (!model.Id.HasValue)
if (model.Id < 0)
{
return null;
}
using var context = new EventVisitorDbContext();
return context.Visitors.
Include(x => x.Event).
FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
FirstOrDefault(x => (x.Id == model.Id))?
.GetViewModel;
}

View File

@ -9,7 +9,7 @@ namespace EventVisitorLogic.BindingModels
{
public class VisitorBindingModel: IVisitorModel
{
public int? Id { get; set; }
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;

View File

@ -91,7 +91,7 @@ namespace EventVisitorLogic.Logic
{
throw new ArgumentNullException("Нет почты", nameof(model.Email));
}
if (model.DayBirth <= DateTime.Now)
if (model.DayBirth >= DateTime.Now)
{
throw new ArgumentNullException("Неверная дата рождения", nameof(model.DayBirth));
}

View File

@ -53,6 +53,19 @@ namespace EventVisitorRestApi.Controllers
}
}
[HttpPost]
public void RegistrationOnEvent(VisitorBindingModel model)
{
try
{
_visitor.Create(model);
}
catch (Exception ex)
{
throw;
}
}
//[HttpGet]