diff --git a/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs b/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs index 134fdbb..7b6ddf5 100644 --- a/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs +++ b/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs @@ -16,6 +16,10 @@ using DocumentFormat.OpenXml.Office2010.Excel; using System.Text; using System.Security.Cryptography; using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Drawing.Diagrams; +using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing; +using DocumentFormat.OpenXml.Wordprocessing; namespace EventVisitorClientApp.Controllers { @@ -306,30 +310,77 @@ namespace EventVisitorClientApp.Controllers /// /// /// + /// public IActionResult Visitors(int id) { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } - var allVisitors = APIClient.GetRequest>($"api/main/GetVisitorList?EventId={id}"); - return View(allVisitors); + // + var visitors = APIClient.GetRequest>($"api/main/GetVisitorList?EventId={id}"); + return View(visitors); + } + [HttpPost] + public IActionResult Visitors(int id, string action, string searchTerm, [FromForm] List presentIds) + { + // + var visitors = APIClient.GetRequest>($"api/main/GetVisitorList?EventId={id}"); + + if (action == "search" && !string.IsNullOrEmpty(searchTerm)) + { + visitors = visitors.Where(v => v.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) || + v.Email.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)).ToList(); + } + + if (action == "save") + { + foreach (var visitor in visitors) + { + var status = presentIds.Contains(visitor.Id) ? "" : ""; + APIClient.PostRequest("api/main/updatevisitor", new VisitorBindingModel + { + Id = visitor.Id, + Status = status + }); + } + + // id + return RedirectToAction("Visitors", new { id }); + } + + return View(visitors); // } - [HttpPost] - public void Visitors(int id, [FromForm] List presentIds) + public IActionResult DeleteVisitor(int id) { - var allVisitors = APIClient.GetRequest>($"api/main/GetVisitorList?EventId={id}"); - - foreach (var visitor in allVisitors) + if (APIClient.Client == null) { - var status = presentIds.Contains(visitor.Id) ? "" : ""; - APIClient.PostRequest("api/main/updatevisitor", new VisitorBindingModel - { - Id = visitor.Id, - Status = status - }); + return Redirect("~/Home/Enter"); } + var existingVisitor = APIClient.GetRequest($"api/main/GetVisitor?VisitorId={id}"); + var existingEvent = APIClient.GetRequest($"api/main/GetEvent?EventId={existingVisitor.EventId}"); + int eventId = existingEvent.Id; + APIClient.PostRequest($"api/main/DeleteVisitor", new VisitorBindingModel { Id = id }); + APIClient.PostRequest("api/main/UpdateEvent", new EventBindingModel + { + Id = existingVisitor.EventId, + Name = existingEvent.Name, + Description = existingEvent.Description, + Type = existingEvent.Type, + ContactPhone = existingEvent.ContactPhone, + Address = existingEvent.Address, + City = existingEvent.City, + Status = existingEvent.Status, + ContactEmail = existingEvent.ContactEmail, + TimeEnd = existingEvent.TimeEnd, + TimeStart = existingEvent.TimeStart, + Date = existingEvent.Date.ToUniversalTime(), + CountVisitors = existingEvent.CountVisitors, + FreePlaces = existingEvent.FreePlaces + 1, + OrganizerId = APIClient.Client.Id + }); + return Redirect($"~/Home/Visitors/{eventId}"); } public IActionResult ResultRegistration() diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/Visitors.cshtml b/EventVisitor/EventVisitorClientApp/Views/Home/Visitors.cshtml index d85ba7e..8607ca8 100644 --- a/EventVisitor/EventVisitorClientApp/Views/Home/Visitors.cshtml +++ b/EventVisitor/EventVisitorClientApp/Views/Home/Visitors.cshtml @@ -9,10 +9,20 @@

Зарегистрированные пользователи

-
-
- @{ - + + + +
+
+ +
+
+ +
+
+ +
+
@@ -20,6 +30,7 @@ + @@ -31,25 +42,28 @@ + }
ИмяТелефон Дата рождения
@Html.DisplayFor(modelItem => item.Phone) @Html.DisplayFor(modelItem => item.DayBirth) -
- - -
+
+ + +
+
+ Удалить
- } - - -
+ + + + \ No newline at end of file diff --git a/EventVisitor/EventVisitorLogic/Logic/VisitorLogic.cs b/EventVisitor/EventVisitorLogic/Logic/VisitorLogic.cs index 346f9c1..4f06255 100644 --- a/EventVisitor/EventVisitorLogic/Logic/VisitorLogic.cs +++ b/EventVisitor/EventVisitorLogic/Logic/VisitorLogic.cs @@ -30,7 +30,6 @@ namespace EventVisitorLogic.Logic public bool Delete(VisitorBindingModel model) { - CheckModel(model, false); if (_visitorStorage.Delete(model) == null) { return false; diff --git a/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs b/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs index 9d16461..7ec844e 100644 --- a/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs +++ b/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs @@ -155,6 +155,21 @@ namespace EventVisitorRestApi.Controllers } } + [HttpGet] + public VisitorViewModel? GetVisitor(int visitorId) + { + try + { + return _visitor.ReadElement(new VisitorBindingModel + { + Id = visitorId + }); + } + catch (Exception ex) + { + throw; + } + } [HttpPost] public void UpdateVisitor(VisitorBindingModel model) { @@ -168,6 +183,19 @@ namespace EventVisitorRestApi.Controllers } } + [HttpPost] + public void DeleteVisitor(VisitorBindingModel model) + { + try + { + _visitor.Delete(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpPost] public void DeleteEvent(EventBindingModel model) {