From b2f1e1c322fd0e3a42784289bb619e419222270e Mon Sep 17 00:00:00 2001 From: EkaterinaR Date: Mon, 4 Nov 2024 19:46:16 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=B5=D1=80=D0=BE=D0=BF=D1=80=D0=B8=D1=8F=D1=82?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= =?UTF-8?q?,=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D1=87=D1=82=D0=B8?= =?UTF-8?q?=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 119 ++++++++++- .../Views/Home/Enter.cshtml | 45 ++-- .../Views/Home/MyEvents.cshtml | 119 +++++------ .../Views/Home/Register.cshtml | 195 +++++++++++------- .../Views/Home/UpdateEvent.cshtml | 106 ++++++++++ .../Views/Home/UpdateEvent.cshtml.cs | 12 ++ .../Views/Home/ViewEvent.cshtml | 86 ++++++++ .../Views/Home/ViewEvent.cshtml.cs | 12 ++ .../Entities/EventEntity.cs | 43 +--- .../Entities/OrganizerEntity.cs | 32 +-- .../Entities/OrganizerEvent.cs | 20 -- .../EventVisitorDbContext.cs | 1 - .../Implements/EventStorage.cs | 15 +- .../Implements/OrganizerStorage.cs | 17 +- ... 20241104114850_InitialCreate.Designer.cs} | 57 +---- ...ate.cs => 20241104114850_InitialCreate.cs} | 44 +--- .../EventVisitorDbContextModelSnapshot.cs | 55 +---- .../BindingModels/EventBindingModel.cs | 9 +- .../EventVisitorLogic/Logic/EventLogic.cs | 4 - .../ViewModels/EventViewModel.cs | 1 + .../EventVisitorModels/IEventModel.cs | 1 + .../Controllers/MainController.cs | 112 +++++----- 22 files changed, 632 insertions(+), 473 deletions(-) create mode 100644 EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml create mode 100644 EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml.cs create mode 100644 EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml create mode 100644 EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml.cs delete mode 100644 EventVisitor/EventVisitorDatabase/Entities/OrganizerEvent.cs rename EventVisitor/EventVisitorDatabase/Migrations/{20241103104453_InitialCreate.Designer.cs => 20241104114850_InitialCreate.Designer.cs} (77%) rename EventVisitor/EventVisitorDatabase/Migrations/{20241103104453_InitialCreate.cs => 20241104114850_InitialCreate.cs} (75%) diff --git a/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs b/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs index dfba737..e03098e 100644 --- a/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs +++ b/EventVisitor/EventVisitorClientApp/Controllers/HomeController.cs @@ -5,7 +5,11 @@ using EventVisitorLogic.ViewModels; using Microsoft.AspNetCore.Mvc; using System; using System.Diagnostics; +using System.Net.NetworkInformation; +using System.Net; +using System.Numerics; using System.Security.Cryptography.Xml; +using System.Xml.Linq; namespace EventVisitorClientApp.Controllers { @@ -31,7 +35,7 @@ namespace EventVisitorClientApp.Controllers { throw new Exception(" "); } - APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); + APIClient.Client = APIClient.GetRequest($"api/Organizer/login?login={login}&password={password}"); if (APIClient.Client == null) { throw new Exception(" /"); @@ -153,19 +157,112 @@ namespace EventVisitorClientApp.Controllers public IActionResult MyEvents() { - //if (APIClient.Client == null) - //{ - // return Redirect("~/Home/Enter"); - //} - return View(APIClient.GetRequest>($"api/main/getevents")); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/main/GetEventList?ClientId={APIClient.Client.Id}")); } public IActionResult CreateEvent() { - //if (APIClient.Client == null) - //{ - // return Redirect("~/Home/Enter"); - //} - return View(); + 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($"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(" ? "); + } + 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 + }); + 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($"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(" "); + } + 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 = timeend.ToUniversalTime(), + TimeStart = timestart.ToUniversalTime(), + Date = DateTime.Now.ToUniversalTime(), + CountVisitors = count, + FreePlaces = count, + OrganizerId = APIClient.Client.Id + }); + Response.Redirect("MyEvents"); } } } diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/Enter.cshtml b/EventVisitor/EventVisitorClientApp/Views/Home/Enter.cshtml index da535b6..cb7fcf1 100644 --- a/EventVisitor/EventVisitorClientApp/Views/Home/Enter.cshtml +++ b/EventVisitor/EventVisitorClientApp/Views/Home/Enter.cshtml @@ -1,21 +1,34 @@ @{ - ViewData["Title"] = "Enter"; + ViewData["Title"] = "Enter"; } -
-

Вход в приложение

+
+

Вход в приложение

+ +
+
+ + +
+
+ + +
+
+ +
+ +
-
-
- - -
-
- - -
-
- -
-
+ \ No newline at end of file diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/MyEvents.cshtml b/EventVisitor/EventVisitorClientApp/Views/Home/MyEvents.cshtml index b719c88..3fb6b6a 100644 --- a/EventVisitor/EventVisitorClientApp/Views/Home/MyEvents.cshtml +++ b/EventVisitor/EventVisitorClientApp/Views/Home/MyEvents.cshtml @@ -2,67 +2,70 @@ @model List @{ - ViewData["Title"] = "MyEvents"; + ViewData["Title"] = "Мои мероприятия"; } -
-

Мои мероприятия

+
+
+

Мои мероприятия

+
+ +
+ @{ + +

+ Создать мероприятие +

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
НазваниеДата началаСтатусСвободные местаДействия
@Html.DisplayFor(modelItem => item.Name)@Html.DisplayFor(modelItem => item.TimeStart)@Html.DisplayFor(modelItem => item.Status)@Html.DisplayFor(modelItem => item.FreePlaces) + Редактировать + Удалить + Посмотреть +
+ } +
-
- @{ - if (Model == null) - { -

Авторизируйтесь

- return; - } + \ No newline at end of file diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/Register.cshtml b/EventVisitor/EventVisitorClientApp/Views/Home/Register.cshtml index f6033c1..63505a4 100644 --- a/EventVisitor/EventVisitorClientApp/Views/Home/Register.cshtml +++ b/EventVisitor/EventVisitorClientApp/Views/Home/Register.cshtml @@ -1,87 +1,132 @@ @{ - ViewData["Title"] = "Register"; + ViewData["Title"] = "Register"; } -
-

Регистрация

-
-
+
+

Регистрация

-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
- +
+
+ + +
Пожалуйста, введите корректный e-mail.
+
+ +
+ + +
Пожалуйста, введите пароль.
+
+ +
+ + +
Пожалуйста, введите фамилию.
+
+ +
+ + +
Пожалуйста, введите имя.
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
Пожалуйста, выберите роль.
+
+ +
+ + +
Пожалуйста, введите номер телефона.
+
+ +
+ +
+
+
+ - // Отправляем форму - document.forms[0].submit(); // Отправляет первую форму на странице - } else { - alert("Введите код подтверждения."); - } - }; - \ No newline at end of file diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml b/EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml new file mode 100644 index 0000000..e975301 --- /dev/null +++ b/EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml @@ -0,0 +1,106 @@ +@using EventVisitorLogic.ViewModels +@model EventViewModel +@{ + ViewData["Title"] = "UpdateEvent"; +} + +
+

Редактирование мероприятия

+
+
+ +
+ +
Пожалуйста, введите название мероприятия.
+
+
+
+ +
+ +
Пожалуйста, выберите дату и время начала.
+
+
+
+ +
+ +
Пожалуйста, выберите дату и время окончания.
+
+
+
+ +
+ +
+
+
+ +
+ +
Пожалуйста, выберите тип мероприятия.
+
+
+
+ +
+ +
Пожалуйста, введите контактный телефон.
+
+
+
+ +
+ +
Пожалуйста, введите корректный email.
+
+
+
+ +
+ +
Пожалуйста, введите адрес.
+
+
+
+ +
+ +
Пожалуйста, введите город.
+
+
+
+ +
+ +
Пожалуйста, выберите статус мероприятия.
+
+
+
+ +
+ +
Пожалуйста, введите количество посетителей.
+
+
+
+
+ +
+
+
diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml.cs b/EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml.cs new file mode 100644 index 0000000..8cfb1ad --- /dev/null +++ b/EventVisitor/EventVisitorClientApp/Views/Home/UpdateEvent.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace EventVisitorClientApp.Views.Home +{ + public class UpdateEventModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml b/EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml new file mode 100644 index 0000000..c5a6d47 --- /dev/null +++ b/EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml @@ -0,0 +1,86 @@ +@using EventVisitorLogic.ViewModels +@model EventViewModel + +@{ + ViewData["Title"] = "Просмотр мероприятия"; +} + +
+
+
+
+
+

@Html.DisplayFor(model => model.Name)

+
+
+

Описание:

+

@Html.DisplayFor(model => model.Description)

+

Дата начала:

+

@Html.DisplayFor(model => model.TimeStart)

+

Дата окончания:

+

@Html.DisplayFor(model => model.TimeEnd)

+

Статус:

+

@Html.DisplayFor(model => model.Status)

+

Город:

+

@Html.DisplayFor(model => model.City)

+

Адресс:

+

@Html.DisplayFor(model => model.Address)

+

Всего мест:

+

@Html.DisplayFor(model => model.CountVisitors)

+

Свободных мест:

+

@Html.DisplayFor(model => model.FreePlaces)

+
+
+
+
+
+
+

Сообщение участникам

+
+
+
+
+ + +
+
+ + +
+ +
+
+
+ + +
+
+
+ + diff --git a/EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml.cs b/EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml.cs new file mode 100644 index 0000000..55de548 --- /dev/null +++ b/EventVisitor/EventVisitorClientApp/Views/Home/ViewEvent.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace EventVisitorClientApp.Views.Home +{ + public class ViewEventModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/EventVisitor/EventVisitorDatabase/Entities/EventEntity.cs b/EventVisitor/EventVisitorDatabase/Entities/EventEntity.cs index b8da2e2..7b1ac98 100644 --- a/EventVisitor/EventVisitorDatabase/Entities/EventEntity.cs +++ b/EventVisitor/EventVisitorDatabase/Entities/EventEntity.cs @@ -42,24 +42,9 @@ namespace EventVisitorDatabase.Entities public int CountVisitors { get; set; } [Required] public int FreePlaces { get; set; } + [Required] + public int OrganizerId { get; set; } - [ForeignKey("EventId")] - public virtual List Organizers { get; set; } = new(); - - private Dictionary? _eventOrginizers = null; - [NotMapped] - public Dictionary OrganizerEvent - { - get - { - if (_eventOrginizers == null) - { - _eventOrginizers = Organizers - .ToDictionary(rec => rec.OrganizerId, rec => (rec.Organizer as OrganizerEntity)); - } - return _eventOrginizers; - } - } public static EventEntity? Create(EventBindingModel model) { @@ -69,7 +54,7 @@ namespace EventVisitorDatabase.Entities } return new EventEntity() { - Id = (int)(model?.Id), + Id = model.Id, Name = model.Name, Date = model.Date, TimeStart = model.TimeStart, @@ -82,7 +67,8 @@ namespace EventVisitorDatabase.Entities City = model.City, Status = model.Status, CountVisitors = model.CountVisitors, - FreePlaces = model.FreePlaces + FreePlaces = model.FreePlaces, + OrganizerId = model.OrganizerId }; } @@ -103,25 +89,11 @@ namespace EventVisitorDatabase.Entities City = model.City, Status = model.Status, CountVisitors = model.CountVisitors, - FreePlaces = model.FreePlaces + FreePlaces = model.FreePlaces, + OrganizerId = model.OrganizerId }; } - public void UpdateOrganizer(EventVisitorDbContext context, EventBindingModel model) - { - var events = context.Events.First(x => x.Id == Id); - foreach (var fs in model.OrganizerEvent) - { - context.OrganizerEvent.Add(new OrganizerEvent - { - Event = events, - Organizer = context.Organizers.First(x => x.Id == fs.Value.Id) - }); - context.SaveChanges(); - } - _eventOrginizers = null; - } - public void Update(EventBindingModel model) { Name = model.Name; @@ -155,6 +127,7 @@ namespace EventVisitorDatabase.Entities Status = Status, CountVisitors = CountVisitors, FreePlaces = FreePlaces, + OrganizerId = OrganizerId }; } } diff --git a/EventVisitor/EventVisitorDatabase/Entities/OrganizerEntity.cs b/EventVisitor/EventVisitorDatabase/Entities/OrganizerEntity.cs index 8fc1468..c678995 100644 --- a/EventVisitor/EventVisitorDatabase/Entities/OrganizerEntity.cs +++ b/EventVisitor/EventVisitorDatabase/Entities/OrganizerEntity.cs @@ -31,23 +31,7 @@ namespace EventVisitorDatabase.Entities [Required] public string Phone { get; set; } = string.Empty; - [ForeignKey("OrganizerId")] - public virtual List Events { get; set; } = new(); - - private Dictionary? _eventOrginizers = null; - [NotMapped] - public Dictionary OrganizerEvent - { - get - { - if (_eventOrginizers == null) - { - _eventOrginizers = Events - .ToDictionary(rec => rec.EventId, rec => (rec.Event as EventEntity)); - } - return _eventOrginizers; - } - } + public static OrganizerEntity? Create(OrganizerBindingModel model) { @@ -85,20 +69,6 @@ namespace EventVisitorDatabase.Entities }; } - public void UpdateEvents(EventVisitorDbContext context, OrganizerBindingModel model) - { - var organizer = context.Organizers.First(x => x.Id == Id); - foreach (var fs in model.OrganizerEvent) - { - context.OrganizerEvent.Add(new OrganizerEvent - { - Organizer = organizer, - Event = context.Events.First(x => x.Id == fs.Value.Id) - }); - context.SaveChanges(); - } - _eventOrginizers = null; - } public void Update(OrganizerBindingModel model) { diff --git a/EventVisitor/EventVisitorDatabase/Entities/OrganizerEvent.cs b/EventVisitor/EventVisitorDatabase/Entities/OrganizerEvent.cs deleted file mode 100644 index 1f95576..0000000 --- a/EventVisitor/EventVisitorDatabase/Entities/OrganizerEvent.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EventVisitorDatabase.Entities -{ - public class OrganizerEvent - { - public int Id { get; set; } - [Required] - public int EventId { get; set; } - [Required] - public int OrganizerId { get; set; } - public virtual EventEntity Event { get; set; } = new(); - public virtual OrganizerEntity Organizer { get; set; } = new(); - } -} diff --git a/EventVisitor/EventVisitorDatabase/EventVisitorDbContext.cs b/EventVisitor/EventVisitorDatabase/EventVisitorDbContext.cs index 8e30d34..468e5b3 100644 --- a/EventVisitor/EventVisitorDatabase/EventVisitorDbContext.cs +++ b/EventVisitor/EventVisitorDatabase/EventVisitorDbContext.cs @@ -17,6 +17,5 @@ namespace EventVisitorDatabase public virtual DbSet Visitors { get; set; } public virtual DbSet Organizers { get; set; } public virtual DbSet Events { get; set; } - public DbSet OrganizerEvent { get; set; } } } diff --git a/EventVisitor/EventVisitorDatabase/Implements/EventStorage.cs b/EventVisitor/EventVisitorDatabase/Implements/EventStorage.cs index 4f38718..b8d3428 100644 --- a/EventVisitor/EventVisitorDatabase/Implements/EventStorage.cs +++ b/EventVisitor/EventVisitorDatabase/Implements/EventStorage.cs @@ -13,7 +13,7 @@ namespace EventVisitorDatabase.Implements public EventViewModel? Delete(EventBindingModel model) { using var context = new EventVisitorDbContext(); - var element = context.Events.Include(x => x.Organizers).ThenInclude(x => x.Organizer).FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Events.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Events.Remove(element); @@ -25,23 +25,20 @@ namespace EventVisitorDatabase.Implements public EventViewModel? GetElement(EventBindingModel model) { - if (!model.Id.HasValue) + if (model.Id < 0) { return null; } using var context = new EventVisitorDbContext(); return context.Events. - Include(x => x.Organizers). - ThenInclude(x => x.Organizer). - FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? + FirstOrDefault(x => (x.Id == model.Id))? .GetViewModel; } public List GetFullList() { using var context = new EventVisitorDbContext(); - return context.Events.Include(x => x.Organizers). - ThenInclude(x => x.Organizer) + return context.Events .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -58,8 +55,6 @@ namespace EventVisitorDatabase.Implements context.Events.Add(newRecipe); context.SaveChanges(); return context.Events - .Include(x => x.Organizers) - .ThenInclude(x => x.Organizer) .FirstOrDefault(x => x.Id == newRecipe.Id) ?.GetViewModel; } @@ -77,8 +72,6 @@ namespace EventVisitorDatabase.Implements } recipe.Update(model); context.SaveChanges(); - if (model.OrganizerEvent != null) - recipe.UpdateOrganizer(context, model); transaction.Commit(); return recipe.GetViewModel; } diff --git a/EventVisitor/EventVisitorDatabase/Implements/OrganizerStorage.cs b/EventVisitor/EventVisitorDatabase/Implements/OrganizerStorage.cs index 5225381..1238d7b 100644 --- a/EventVisitor/EventVisitorDatabase/Implements/OrganizerStorage.cs +++ b/EventVisitor/EventVisitorDatabase/Implements/OrganizerStorage.cs @@ -16,7 +16,7 @@ namespace EventVisitorDatabase.Implements public OrganizerViewModel? Delete(OrganizerBindingModel model) { using var context = new EventVisitorDbContext(); - var element = context.Organizers.Include(x => x.Events).ThenInclude(x => x.Event).FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Organizers.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Organizers.Remove(element); @@ -28,14 +28,15 @@ namespace EventVisitorDatabase.Implements public OrganizerViewModel? GetElement(OrganizerBindingModel model) { - if (model.Id > 0) + if (model.Id < 0) { return null; } using var context = new EventVisitorDbContext(); + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + return context.Organizers.FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))?.GetViewModel; + return context.Organizers. - Include(x => x.Events). - ThenInclude(x => x.Event). FirstOrDefault(x => (x.Id == model.Id))? .GetViewModel; } @@ -43,13 +44,13 @@ namespace EventVisitorDatabase.Implements public List GetFullList() { using var context = new EventVisitorDbContext(); - return context.Organizers.Include(x => x.Events). - ThenInclude(x => x.Event) + return context.Organizers .ToList() .Select(x => x.GetViewModel) .ToList(); } + public OrganizerViewModel? Insert(OrganizerBindingModel model) { using var context = new EventVisitorDbContext(); @@ -61,8 +62,6 @@ namespace EventVisitorDatabase.Implements context.Organizers.Add(newRecipe); context.SaveChanges(); return context.Organizers - .Include(x => x.Events) - .ThenInclude(x => x.Event) .FirstOrDefault(x => x.Id == newRecipe.Id) ?.GetViewModel; } @@ -80,8 +79,6 @@ namespace EventVisitorDatabase.Implements } recipe.Update(model); context.SaveChanges(); - if (model.OrganizerEvent != null) - recipe.UpdateEvents(context, model); transaction.Commit(); return recipe.GetViewModel; } diff --git a/EventVisitor/EventVisitorDatabase/Migrations/20241103104453_InitialCreate.Designer.cs b/EventVisitor/EventVisitorDatabase/Migrations/20241104114850_InitialCreate.Designer.cs similarity index 77% rename from EventVisitor/EventVisitorDatabase/Migrations/20241103104453_InitialCreate.Designer.cs rename to EventVisitor/EventVisitorDatabase/Migrations/20241104114850_InitialCreate.Designer.cs index 08c2d53..35c396c 100644 --- a/EventVisitor/EventVisitorDatabase/Migrations/20241103104453_InitialCreate.Designer.cs +++ b/EventVisitor/EventVisitorDatabase/Migrations/20241104114850_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace EventVisitorDatabase.Migrations { [DbContext(typeof(EventVisitorDbContext))] - [Migration("20241103104453_InitialCreate")] + [Migration("20241104114850_InitialCreate")] partial class InitialCreate { /// @@ -66,6 +66,9 @@ namespace EventVisitorDatabase.Migrations .IsRequired() .HasColumnType("text"); + b.Property("OrganizerId") + .HasColumnType("integer"); + b.Property("Status") .IsRequired() .HasColumnType("text"); @@ -130,29 +133,6 @@ namespace EventVisitorDatabase.Migrations b.ToTable("Organizers"); }); - modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("EventId") - .HasColumnType("integer"); - - b.Property("OrganizerId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("EventId"); - - b.HasIndex("OrganizerId"); - - b.ToTable("OrganizerEvent"); - }); - modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b => { b.Property("Id") @@ -190,25 +170,6 @@ namespace EventVisitorDatabase.Migrations b.ToTable("Visitors"); }); - modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEvent", b => - { - b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event") - .WithMany("Organizers") - .HasForeignKey("EventId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EventVisitorDatabase.Entities.OrganizerEntity", "Organizer") - .WithMany("Events") - .HasForeignKey("OrganizerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Event"); - - b.Navigation("Organizer"); - }); - modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b => { b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event") @@ -219,16 +180,6 @@ namespace EventVisitorDatabase.Migrations b.Navigation("Event"); }); - - modelBuilder.Entity("EventVisitorDatabase.Entities.EventEntity", b => - { - b.Navigation("Organizers"); - }); - - modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEntity", b => - { - b.Navigation("Events"); - }); #pragma warning restore 612, 618 } } diff --git a/EventVisitor/EventVisitorDatabase/Migrations/20241103104453_InitialCreate.cs b/EventVisitor/EventVisitorDatabase/Migrations/20241104114850_InitialCreate.cs similarity index 75% rename from EventVisitor/EventVisitorDatabase/Migrations/20241103104453_InitialCreate.cs rename to EventVisitor/EventVisitorDatabase/Migrations/20241104114850_InitialCreate.cs index 451c789..70acd67 100644 --- a/EventVisitor/EventVisitorDatabase/Migrations/20241103104453_InitialCreate.cs +++ b/EventVisitor/EventVisitorDatabase/Migrations/20241104114850_InitialCreate.cs @@ -30,7 +30,8 @@ namespace EventVisitorDatabase.Migrations City = table.Column(type: "text", nullable: false), Status = table.Column(type: "text", nullable: false), CountVisitors = table.Column(type: "integer", nullable: false), - FreePlaces = table.Column(type: "integer", nullable: false) + FreePlaces = table.Column(type: "integer", nullable: false), + OrganizerId = table.Column(type: "integer", nullable: false) }, constraints: table => { @@ -81,42 +82,6 @@ namespace EventVisitorDatabase.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "OrganizerEvent", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - EventId = table.Column(type: "integer", nullable: false), - OrganizerId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_OrganizerEvent", x => x.Id); - table.ForeignKey( - name: "FK_OrganizerEvent_Events_EventId", - column: x => x.EventId, - principalTable: "Events", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_OrganizerEvent_Organizers_OrganizerId", - column: x => x.OrganizerId, - principalTable: "Organizers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_OrganizerEvent_EventId", - table: "OrganizerEvent", - column: "EventId"); - - migrationBuilder.CreateIndex( - name: "IX_OrganizerEvent_OrganizerId", - table: "OrganizerEvent", - column: "OrganizerId"); - migrationBuilder.CreateIndex( name: "IX_Visitors_EventId", table: "Visitors", @@ -127,14 +92,11 @@ namespace EventVisitorDatabase.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "OrganizerEvent"); + name: "Organizers"); migrationBuilder.DropTable( name: "Visitors"); - migrationBuilder.DropTable( - name: "Organizers"); - migrationBuilder.DropTable( name: "Events"); } diff --git a/EventVisitor/EventVisitorDatabase/Migrations/EventVisitorDbContextModelSnapshot.cs b/EventVisitor/EventVisitorDatabase/Migrations/EventVisitorDbContextModelSnapshot.cs index 0d7c6d0..8c70b97 100644 --- a/EventVisitor/EventVisitorDatabase/Migrations/EventVisitorDbContextModelSnapshot.cs +++ b/EventVisitor/EventVisitorDatabase/Migrations/EventVisitorDbContextModelSnapshot.cs @@ -63,6 +63,9 @@ namespace EventVisitorDatabase.Migrations .IsRequired() .HasColumnType("text"); + b.Property("OrganizerId") + .HasColumnType("integer"); + b.Property("Status") .IsRequired() .HasColumnType("text"); @@ -127,29 +130,6 @@ namespace EventVisitorDatabase.Migrations b.ToTable("Organizers"); }); - modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEvent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("EventId") - .HasColumnType("integer"); - - b.Property("OrganizerId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("EventId"); - - b.HasIndex("OrganizerId"); - - b.ToTable("OrganizerEvent"); - }); - modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b => { b.Property("Id") @@ -187,25 +167,6 @@ namespace EventVisitorDatabase.Migrations b.ToTable("Visitors"); }); - modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEvent", b => - { - b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event") - .WithMany("Organizers") - .HasForeignKey("EventId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EventVisitorDatabase.Entities.OrganizerEntity", "Organizer") - .WithMany("Events") - .HasForeignKey("OrganizerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Event"); - - b.Navigation("Organizer"); - }); - modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b => { b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event") @@ -216,16 +177,6 @@ namespace EventVisitorDatabase.Migrations b.Navigation("Event"); }); - - modelBuilder.Entity("EventVisitorDatabase.Entities.EventEntity", b => - { - b.Navigation("Organizers"); - }); - - modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEntity", b => - { - b.Navigation("Events"); - }); #pragma warning restore 612, 618 } } diff --git a/EventVisitor/EventVisitorLogic/BindingModels/EventBindingModel.cs b/EventVisitor/EventVisitorLogic/BindingModels/EventBindingModel.cs index 045545e..6c00275 100644 --- a/EventVisitor/EventVisitorLogic/BindingModels/EventBindingModel.cs +++ b/EventVisitor/EventVisitorLogic/BindingModels/EventBindingModel.cs @@ -10,7 +10,7 @@ namespace EventVisitorLogic.BindingModels { public class EventBindingModel: IEventModel { - public int? Id { get; set; } + public int Id { get; set; } public string Name { get; set; } = string.Empty; public DateTime Date { get; set; } public DateTime TimeStart { get; set; } @@ -24,11 +24,6 @@ namespace EventVisitorLogic.BindingModels public string Status { get; set; } = string.Empty; public int CountVisitors { get; set; } public int FreePlaces { get; set; } - - public Dictionary OrganizerEvent - { - get; - set; - } = new(); + public int OrganizerId { get; set; } } } diff --git a/EventVisitor/EventVisitorLogic/Logic/EventLogic.cs b/EventVisitor/EventVisitorLogic/Logic/EventLogic.cs index 62d6d7a..6e52190 100644 --- a/EventVisitor/EventVisitorLogic/Logic/EventLogic.cs +++ b/EventVisitor/EventVisitorLogic/Logic/EventLogic.cs @@ -111,10 +111,6 @@ namespace EventVisitorLogic.Logic { throw new ArgumentNullException("Некорректный количество посетителей, nameof(model.CountVisitors)"); } - if (model.Date <= DateTime.Now.AddHours(2)) - { - throw new ArgumentNullException("Нельзя выбрать дату меньше сегодняшней", nameof(model.Date)); - } if (model.TimeStart <= DateTime.Now.AddHours(2)) { throw new ArgumentNullException("Нельзя выбрать время меньше, чем через 2 часа от текущего", nameof(model.Date)); diff --git a/EventVisitor/EventVisitorLogic/ViewModels/EventViewModel.cs b/EventVisitor/EventVisitorLogic/ViewModels/EventViewModel.cs index 3067ed9..c3b3704 100644 --- a/EventVisitor/EventVisitorLogic/ViewModels/EventViewModel.cs +++ b/EventVisitor/EventVisitorLogic/ViewModels/EventViewModel.cs @@ -23,5 +23,6 @@ namespace EventVisitorLogic.ViewModels public string Status { get; set; } = string.Empty; public int CountVisitors { get; set; } public int FreePlaces { get; set; } + public int OrganizerId { get; set; } } } diff --git a/EventVisitor/EventVisitorModels/IEventModel.cs b/EventVisitor/EventVisitorModels/IEventModel.cs index ef21bb0..772b1a6 100644 --- a/EventVisitor/EventVisitorModels/IEventModel.cs +++ b/EventVisitor/EventVisitorModels/IEventModel.cs @@ -22,6 +22,7 @@ namespace EventVisitorModels public string Status { get; set; } = string.Empty; public int CountVisitors { get; set; } public int FreePlaces { get; set; } + public int OrganizerId { get; set; } } } diff --git a/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs b/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs index c2298ba..a8f3dc2 100644 --- a/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs +++ b/EventVisitor/EventVisitorRestApi/Controllers/MainController.cs @@ -21,21 +21,40 @@ namespace EventVisitorRestApi.Controllers } /// Мероприятия [HttpGet] - public List? GetEvents() + public List? GetEventList(int organizerId) { try { - //if (clientId == null) - //{ - // return _event.ReadList(null); - //} - return _event.ReadList(null); + if (organizerId == null) + { + return _event.ReadList(null); + } + return _event.ReadList(new EventBindingModel + { + OrganizerId = organizerId + }); } catch (Exception ex) { throw; } } + + [HttpPost] + public void CreateEvent(EventBindingModel model) + { + try + { + _event.Create(model); + } + catch (Exception ex) + { + throw; + } + } + + + //[HttpGet] //public List? GetProcedures() //{ @@ -155,22 +174,21 @@ namespace EventVisitorRestApi.Controllers // throw; // } //} - //[HttpGet] - //public MedicinesViewModel? GetMedicine(int medicineId) - //{ - // try - // { - // return _medicine.ReadElement(new MedicinesSearchModel - // { - // Id = medicineId - // }); - // } - // catch (Exception ex) - // { - // _logger.LogError(ex, "Ошибка получения лекарства по id={Id}", medicineId); - // throw; - // } - //} + [HttpGet] + public EventViewModel? GetEvent(int eventId) + { + try + { + return _event.ReadElement(new EventBindingModel + { + Id = eventId + }); + } + catch (Exception ex) + { + throw; + } + } //[HttpPost] //public void CreateMedicine(MedicinesBindingModel model) @@ -185,33 +203,31 @@ namespace EventVisitorRestApi.Controllers // throw; // } //} - //[HttpPost] - //public void UpdateMedicine(MedicinesBindingModel model) - //{ - // try - // { - // _medicine.Update(model); - // } - // catch (Exception ex) - // { - // _logger.LogError(ex, "Ошибка обновления лекарства"); - // throw; - // } - //} + [HttpPost] + public void UpdateEvent(EventBindingModel model) + { + try + { + _event.Update(model); + } + catch (Exception ex) + { + throw; + } + } - //[HttpPost] - //public void DeleteMedicine(MedicinesBindingModel model) - //{ - // try - // { - // _medicine.Delete(model); - // } - // catch (Exception ex) - // { - // _logger.LogError(ex, "Ошибка удаления лекарства"); - // throw; - // } - //} + [HttpPost] + public void DeleteEvent(EventBindingModel model) + { + try + { + _event.Delete(model); + } + catch (Exception ex) + { + throw; + } + } ///// ///// РЕЦЕПТЫ