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

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); 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] [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) 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("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì"); throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
} }
string eventId = Guid.NewGuid().ToString(); // Ãåíåðàöèÿ óíèêàëüíîãî èäåíòèôèêàòîðà äëÿ ìåðîïðèÿòèÿ
string registrationLink = $"https://localhost:7186/registrationonevent?EventId={eventId}"; // Ôîðìèðîâàíèå ññûëêè íà ðåãèñòðàöèþ
APIClient.PostRequest("api/main/createevent", new EventBindingModel APIClient.PostRequest("api/main/createevent", new EventBindingModel
{ {
Name = name, Name = name,
@ -208,7 +241,7 @@ namespace EventVisitorClientApp.Controllers
CountVisitors = count, CountVisitors = count,
FreePlaces = count, FreePlaces = count,
OrganizerId = APIClient.Client.Id, OrganizerId = APIClient.Client.Id,
Link = "Îòñóòñòâóåò" Link = registrationLink
}); });
Response.Redirect("MyEvents"); Response.Redirect("MyEvents");
} }
@ -239,17 +272,6 @@ namespace EventVisitorClientApp.Controllers
return View(eventDetails); 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] [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 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>
</div> </div>
</form> </form>
</div>

View File

@ -1,40 +1,75 @@
@{ @using EventVisitorLogic.ViewModels
@model EventViewModel
@{
ViewData["Title"] = "RegistrationOnEvent"; ViewData["Title"] = "RegistrationOnEvent";
} }
<div class="containerenter text-center mt-5"> <div class="container mt-5">
<h2 class="display-4 mb-4">Регистрация на мероприятие</h2> <div class="row">
<div class="col-md-6">
<form method="post" class="border p-4 rounded"> <div class="card" style="margin: 10px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); border-radius: 10px;">
<div class="mb-4"> <div class="card-header bg-secondary text-light">
<label for="InputName" class="form-label" style="font-size: 24px" ;>Введите имя</label> <h2>@Html.DisplayFor(model => model.Name)</h2>
<input type="text" name="name" class="form-control" id="name" required> </div>
<div class="invalid-feedback">Пожалуйста, введите имя.</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>
<div class="col-md-6">
<div class="containerenter text-center">
<h2 class="display-4 mb-4">Регистрация на мероприятие</h2>
<div class="mb-4"> <form method="post" class="border p-4 rounded">
<label for="InputPhone" class="form-label" style="font-size: 24px">Введите телефон</label> <div class="mb-4">
<input type="text" name="phone" class="form-control" id="phone" required> <label for="InputName" class="form-label" style="font-size: 24px;">Введите имя</label>
<div class="invalid-feedback">Пожалуйста, введите номер телефона.</div> <input type="text" name="name" class="form-control" id="name" required>
</div> <div class="invalid-feedback">Пожалуйста, введите имя.</div>
</div>
<div class="mb-4"> <div class="mb-4">
<label for="InputEmail" class="form-label" style="font-size: 24px">Введите e-mail</label> <label for="InputPhone" class="form-label" style="font-size: 24px">Введите телефон</label>
<input type="text" name="email" class="form-control" id="email" required> <input type="text" name="phone" class="form-control" id="phone" required>
<div class="invalid-feedback">Пожалуйста, введите e-mail.</div> <div class="invalid-feedback">Пожалуйста, введите номер телефона.</div>
</div> </div>
<div class="mb-4"> <div class="mb-4">
<label for="InputI" class="form-label" style="font-size: 24px">Введите дату рождения</label> <label for="InputEmail" class="form-label" style="font-size: 24px">Введите e-mail</label>
<input type="datetime-local" class="form-control" id="dayBirth" name="dayBirth" required> <input type="text" name="email" class="form-control" id="email" required>
<div class="invalid-feedback">Пожалуйста, введите дату рождения.</div> <div class="invalid-feedback">Пожалуйста, введите e-mail.</div>
</div> </div>
<div class="mb-4"> <div class="mb-4">
<button type="submit" class="btn btn-dark btn-lg w-100">Зарегистрироваться</button> <label for="InputI" class="form-label" style="font-size: 24px">Введите дату рождения</label>
<input type="datetime-local" class="form-control" id="dayBirth" name="dayBirth" required>
<div class="invalid-feedback">Пожалуйста, введите дату рождения.</div>
</div>
<div class="mb-4">
<button type="submit" class="btn btn-dark btn-lg w-100">Зарегистрироваться</button>
</div>
</form>
</div>
</div> </div>
</form> </div>
</div> </div>
<style> <style>
.containerenter { .containerenter {
max-width: 500px; max-width: 500px;
@ -44,11 +79,3 @@
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
} }
</style> </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> </form>
</div> </div>
</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> <button type="submit" class="btn btn-black btn-block">Зарегистрованные пользователи</button>
</div> </div>
</div> </div>

View File

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

View File

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

View File

@ -9,7 +9,7 @@ namespace EventVisitorLogic.BindingModels
{ {
public class VisitorBindingModel: IVisitorModel public class VisitorBindingModel: IVisitorModel
{ {
public int? Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty; public string Phone { get; set; } = string.Empty;
public string Email { 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)); throw new ArgumentNullException("Нет почты", nameof(model.Email));
} }
if (model.DayBirth <= DateTime.Now) if (model.DayBirth >= DateTime.Now)
{ {
throw new ArgumentNullException("Неверная дата рождения", nameof(model.DayBirth)); 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] //[HttpGet]