бд почти готова

This commit is contained in:
EkaterinaR 2024-11-03 01:20:30 +04:00
parent 0a1b1dbf1f
commit b105074910
43 changed files with 1256 additions and 34 deletions

View File

@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventVisitor", "EventVisitor\EventVisitor.csproj", "{DD2EF9ED-BEB4-4BEB-B66E-BF8C3CD61824}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventVisitor", "EventVisitor\EventVisitor.csproj", "{DD2EF9ED-BEB4-4BEB-B66E-BF8C3CD61824}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventVisitorRestApi", "EventVisitorRestApi\EventVisitorRestApi.csproj", "{7BBA67F5-8003-4BC6-9D0E-336C19865729}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventVisitorDatabase", "EventVisitorDatabase\EventVisitorDatabase.csproj", "{FD45483C-2FF2-4668-81DA-6201F6A8D04E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventVisitorModels", "EventVisitorModels\EventVisitorModels.csproj", "{5BC5980E-EDF0-4E84-92B4-12AD969EBD77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventVisitorLogic", "EventVisitorLogic\EventVisitorLogic.csproj", "{E6783173-721A-4A13-A44D-5C9330541BF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +23,22 @@ Global
{DD2EF9ED-BEB4-4BEB-B66E-BF8C3CD61824}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD2EF9ED-BEB4-4BEB-B66E-BF8C3CD61824}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD2EF9ED-BEB4-4BEB-B66E-BF8C3CD61824}.Release|Any CPU.Build.0 = Release|Any CPU
{7BBA67F5-8003-4BC6-9D0E-336C19865729}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BBA67F5-8003-4BC6-9D0E-336C19865729}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BBA67F5-8003-4BC6-9D0E-336C19865729}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BBA67F5-8003-4BC6-9D0E-336C19865729}.Release|Any CPU.Build.0 = Release|Any CPU
{FD45483C-2FF2-4668-81DA-6201F6A8D04E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD45483C-2FF2-4668-81DA-6201F6A8D04E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD45483C-2FF2-4668-81DA-6201F6A8D04E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD45483C-2FF2-4668-81DA-6201F6A8D04E}.Release|Any CPU.Build.0 = Release|Any CPU
{5BC5980E-EDF0-4E84-92B4-12AD969EBD77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BC5980E-EDF0-4E84-92B4-12AD969EBD77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BC5980E-EDF0-4E84-92B4-12AD969EBD77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BC5980E-EDF0-4E84-92B4-12AD969EBD77}.Release|Any CPU.Build.0 = Release|Any CPU
{E6783173-721A-4A13-A44D-5C9330541BF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6783173-721A-4A13-A44D-5C9330541BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6783173-721A-4A13-A44D-5C9330541BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6783173-721A-4A13-A44D-5C9330541BF5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -6,4 +6,25 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Content Remove="Pages\Events\EventRegister.cshtml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Font.Awesome" Version="5.15.4" />
<PackageReference Include="FontAwesome" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Pages\Events\EventRegister.cshtml" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Pages\Events\EventRegister.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="Pages\Events\EventRegister.cshtml" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,23 @@
@page
@model EventVisitor.Pages.EnterModel
@{
ViewData["Title"] = "Enter";
}
<div class="text-center">
<h2 class="display-4">Вход в приложение</h2>
</div>
<form method ="post">
<div class="mb-3">
<label for="InputEmail1" class="form-label" style="font-size: 30px;">Введите e-mail</label>
<input type="email" name="login" class="form-control" id="InputEmail1" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="InputPassword1" class="form-label" style="font-size: 30px";>Введите пароль</label>
<input type="password" name="password" class="form-control" id="InputPassword1">
</div>
<div class="mb-3" style="width: 100%">
<button type="submit" style="background-color:black; width: 100%; font-size: 30px;" class="btn btn-primary">Войти</button>
</div>
</form>

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace EventVisitor.Pages
{
public class EnterModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@ -0,0 +1,4 @@
@page
@model EventVisitor.Pages.Events.EventRegisterModel
@{
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace EventVisitor.Pages.Events
{
public class EventRegisterModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@ -0,0 +1,58 @@
@page
@model EventVisitor.Pages.Events.MyEventsModel
@{
ViewData["Title"] = "MyEvents";
}
<div class="text-center">
<h1 class="display-4">Мои мероприятия</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a class="btn btn-warning" asp-action="CreateEvent">Создать мероприятие</a>
<a class="btn btn-warning" asp-action="DeleteEvent">Удалить</a>
<a class="btn btn-warning" asp-action="UpdateEvent">Редактировать</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название мероприятия
</th>
<th>
Тип мероприятия
</th>
<th>
Вместимость
</th>
<th>
Количество зарегистрированных
</th>
<th>
Место
</th>
<th>
Дата и время начала
</th>
<th>
Описание
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
}
</div>

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace EventVisitor.Pages.Events
{
public class MyEventsModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@ -4,7 +4,27 @@
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8 text-center">
<h1 class="display-4 mb-4">Добро пожаловать в сервис учета посетителей мероприятий</h1>
<p class="lead mb-4">Здесь вы сможете:</p>
<ul class="list-unstyled">
<li class="mb-2">
<i class="fas fa-calendar-plus fa-fw mr-2"></i> Создать мероприятие
</li>
<li class="mb-2">
<i class="fas fa-user-plus fa-fw mr-2"></i> Зарегистрироваться на мероприятие
</li>
<li class="mb-2">
<i class="fas fa-check-circle fa-fw mr-2"></i> Отмечать посещение
</li>
<li class="mb-2">
<i class="fas fa-file-download fa-fw mr-2"></i> Выгружать отчеты о прошедших мероприятиях
</li>
</ul>
</div>
</div>
</div>

View File

@ -1,8 +0,0 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@ -1,20 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace EventVisitor.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;
public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
}
}

View File

@ -0,0 +1,37 @@
@page
@model EventVisitor.Pages.RegistrationModel
@{
ViewData["Title"] = "Register";
}
<div class="text-center">
<h2 class="display-4">Регистрация</h2>
</div>
<form method="post">
<div class="mb-3">
<label for="InputEmail1" class="form-label">Введите e-mail</label>
<input type="email" name="login" class="form-control" id="InputEmail1" aria-describedby="emailHelp">
</div>
<div class="mb-3">
<label for="InputPassword1" class="form-label">Введите пароль</label>
<input type="password" name="password" class="form-control" id="InputPassword1">
</div>
<div class="mb-3">
<label for="InputF" class="form-label">Введите фамилию</label>
<input type="text" name="fio" class="form-control" id="InputF" />
</div>
<div class="mb-3">
<label for="InputI" class="form-label">Введите имя</label>
<input type="text" name="fio" class="form-control" id="InputI" />
</div>
<div class="mb-3">
<label for="InputO" class="form-label">Введите отчество</label>
<input type="text" name="fio" class="form-control" id="InputO" />
</div>
<div class="mb-3" style="width: 100%">
<button type="submit" style="background-color:black; width: 100%; font-size: 30px;" class="btn btn-primary"> Регистрация </button>
</div>
</form>

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace EventVisitor.Pages
{
public class RegistrationModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@ -20,10 +20,16 @@
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Главная</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
<a class="nav-link text-dark" asp-area="" asp-page="/Enter">Вход</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Registration">Регистрация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Events/MyEvents">Moи мероприятия</a>
</li>
</ul>
</div>

View File

@ -0,0 +1,149 @@
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Xml.Linq;
using EventVisitorLogic.ViewModels;
using EventVisitorLogic.BindingModels;
namespace EventVisitorDatabase.Entities
{
public class EventEntity
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public DateTime Date { get; set; }
public DateTime TimeStart { get; set; }
public DateTime TimeEnd { get; set; }
public string Description { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string ContactPhone { get; set; } = string.Empty;
public string ContactEmail { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public int CountVisitors { get; set; }
public int FreePlaces { get; set; }
[ForeignKey("EventId")]
public virtual List<OrganizerEvent> Organizers { get; set; } = new();
private Dictionary<int, OrganizerEntity>? _eventOrginizers = null;
[NotMapped]
public Dictionary<int, OrganizerEntity> OrganizerEvent
{
get
{
if (_eventOrginizers == null)
{
_eventOrginizers = Organizers
.ToDictionary(rec => rec.OrganizerId, rec => (rec.Organizer as OrganizerEntity));
}
return _eventOrginizers;
}
}
public static EventEntity? Create(EventBindingModel model)
{
if (model == null)
{
return null;
}
return new EventEntity()
{
Id = (int)(model?.Id),
Name = model.Name,
Date = model.Date,
TimeStart = model.TimeStart,
TimeEnd = model.TimeEnd,
Description = model.Description,
Type = model.Type,
ContactPhone = model.ContactPhone,
ContactEmail = model.ContactEmail,
Address = model.Address,
City = model.City,
Status = model.Status,
CountVisitors = model.CountVisitors,
FreePlaces = model.FreePlaces
};
}
public static EventEntity Create(EventViewModel model)
{
return new EventEntity()
{
Id = model.Id,
Name = model.Name,
Date = model.Date,
TimeStart = model.TimeStart,
TimeEnd = model.TimeEnd,
Description = model.Description,
Type = model.Type,
ContactPhone = model.ContactPhone,
ContactEmail = model.ContactEmail,
Address = model.Address,
City = model.City,
Status = model.Status,
CountVisitors = model.CountVisitors,
FreePlaces = model.FreePlaces
};
}
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;
Date = model.Date;
TimeStart = model.TimeStart;
TimeEnd = model.TimeEnd;
Description = model.Description;
Type = model.Type;
ContactPhone = model.ContactPhone;
ContactEmail = model.ContactEmail;
Address = model.Address;
City = model.City;
Status = model.Status;
CountVisitors = model.CountVisitors;
FreePlaces = model.FreePlaces;
}
public EventViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Date = Date,
TimeStart = TimeStart,
TimeEnd = TimeEnd,
Description = Description,
Type = Type,
ContactPhone = ContactPhone,
ContactEmail = ContactEmail,
Address = Address,
City = City,
Status = Status,
CountVisitors = CountVisitors,
FreePlaces = FreePlaces,
};
}
}

View File

@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
namespace EventVisitorDatabase.Entities
{
public class OrganizerEntity
{
public int Id { get; set; }
public string Surname { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string OrganizationName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
[ForeignKey("OrganizerId")]
public virtual List<OrganizerEvent> Events { get; set; } = new();
private Dictionary<int, EventEntity>? _eventOrginizers = null;
[NotMapped]
public Dictionary<int, EventEntity> OrganizerEvent
{
get
{
if (_eventOrginizers == null)
{
_eventOrginizers = Events
.ToDictionary(rec => rec.EventId, rec => (rec.Event as EventEntity));
}
return _eventOrginizers;
}
}
public static OrganizerEntity? Create(OrganizerBindingModel model)
{
if (model == null)
{
return null;
}
return new OrganizerEntity()
{
Id = (int)(model?.Id),
Name = model.Name,
Phone = model.Phone,
Role = model.Role,
Surname = model.Surname,
LastName = model.LastName,
OrganizationName = model.OrganizationName
};
}
public static OrganizerEntity Create(OrganizerViewModel model)
{
return new OrganizerEntity()
{
Id = model.Id,
Name = model.Name,
Phone = model.Phone,
Role = model.Role,
Surname = model.Surname,
LastName = model.LastName,
OrganizationName = model.OrganizationName
};
}
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)
{
Name = model.Name;
Phone = model.Phone;
Role = model.Role;
Surname = model.Surname;
LastName = model.LastName;
OrganizationName = model.OrganizationName;
}
public OrganizerViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Phone = Phone,
Role = Role,
Surname = Surname,
LastName = LastName,
OrganizationName = OrganizationName
};
}
}

View File

@ -0,0 +1,20 @@
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();
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorDatabase.Entities
{
public class VisitorEntity
{
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;
public DateTime DayBirth { get; set; }
public string Status { get; set; } = string.Empty;
public int EventId { get; set; }
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventVisitorLogic\EventVisitorLogic.csproj" />
<ProjectReference Include="..\EventVisitorModels\EventVisitorModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,22 @@
using EventVisitorDatabase.Entities;
using Microsoft.EntityFrameworkCore;
namespace EventVisitorDatabase
{
public class EventVisitorDbContext: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=EventVisitorBd;Username=postgres;Password=1234");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<VisitorEntity> VisitorEntities { get; set; }
public virtual DbSet<OrganizerEntity> Organizers { get; set; }
public virtual DbSet<EventEntity> Events { get; set; }
public DbSet<OrganizerEvent> OrganizerEvent { get; set; }
}
}

View File

@ -0,0 +1,92 @@
using EventVisitorDatabase.Entities;
using Microsoft.EntityFrameworkCore;
using EventVisitorLogic.StoragesContracts;
using EventVisitorModels;
using System;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
namespace EventVisitorDatabase.Implements
{
public class EventStorage: IEventStorage
{
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);
if (element != null)
{
context.Events.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public EventViewModel? GetElement(EventBindingModel model)
{
if (!model.Id.HasValue)
{
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))?
.GetViewModel;
}
public List<EventViewModel> GetFullList()
{
using var context = new EventVisitorDbContext();
return context.Events.Include(x => x.Organizers).
ThenInclude(x => x.Organizer)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public EventViewModel? Insert(EventBindingModel model)
{
using var context = new EventVisitorDbContext();
var newRecipe = EventEntity.Create(model);
if (newRecipe == null)
{
return null;
}
context.Events.Add(newRecipe);
context.SaveChanges();
return context.Events
.Include(x => x.Organizers)
.ThenInclude(x => x.Organizer)
.FirstOrDefault(x => x.Id == newRecipe.Id)
?.GetViewModel;
}
public EventViewModel? Update(EventBindingModel model)
{
using var context = new EventVisitorDbContext();
using var transaction = context.Database.BeginTransaction();
try
{
var recipe = context.Events.FirstOrDefault(x => x.Id == model.Id);
if (recipe == null)
{
return null;
}
recipe.Update(model);
context.SaveChanges();
if (model.OrganizerEvent != null)
recipe.UpdateOrganizer(context, model);
transaction.Commit();
return recipe.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,95 @@
using EventVisitorDatabase.Entities;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.StoragesContracts;
using EventVisitorLogic.ViewModels;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorDatabase.Implements
{
public class OrganizerStorage: IOrganizerStorage
{
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);
if (element != null)
{
context.Organizers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public OrganizerViewModel? GetElement(OrganizerBindingModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new EventVisitorDbContext();
return context.Organizers.
Include(x => x.Events).
ThenInclude(x => x.Event).
FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public List<OrganizerViewModel> GetFullList()
{
using var context = new EventVisitorDbContext();
return context.Organizers.Include(x => x.Events).
ThenInclude(x => x.Event)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public OrganizerViewModel? Insert(OrganizerBindingModel model)
{
using var context = new EventVisitorDbContext();
var newRecipe = OrganizerEntity.Create(model);
if (newRecipe == null)
{
return null;
}
context.Organizers.Add(newRecipe);
context.SaveChanges();
return context.Organizers
.Include(x => x.Events)
.ThenInclude(x => x.Event)
.FirstOrDefault(x => x.Id == newRecipe.Id)
?.GetViewModel;
}
public OrganizerViewModel? Update(OrganizerBindingModel model)
{
using var context = new EventVisitorDbContext();
using var transaction = context.Database.BeginTransaction();
try
{
var recipe = context.Organizers.FirstOrDefault(x => x.Id == model.Id);
if (recipe == null)
{
return null;
}
recipe.Update(model);
context.SaveChanges();
if (model.OrganizerEvent != null)
recipe.UpdateEvents(context, model);
transaction.Commit();
return recipe.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,71 @@
using EventVisitorDatabase.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorDatabase.Implements
{
public class VisitorStorage
{
private readonly EventVisitorDbContext _context;
public VisitorStorage(EventVisitorDbContext context)
{
_context = context;
}
public VisitorEntity? GetElement(int id)
{
return _context.VisitorEntities.FirstOrDefault(v => v.Id == id);
}
public List<VisitorEntity> GetList()
{
return _context.VisitorEntities.ToList();
}
public List<VisitorEntity> GetListByEventId(int eventId)
{
return _context.VisitorEntities.Where(v => v.EventId == eventId).ToList();
}
public VisitorEntity Insert(VisitorEntity visitorEntity)
{
_context.VisitorEntities.Add(visitorEntity);
_context.SaveChanges();
return visitorEntity;
}
public VisitorEntity Update(int id, VisitorEntity visitorEntity)
{
var existingVisitor = _context.VisitorEntities.FirstOrDefault(v => v.Id == id);
if (existingVisitor != null)
{
existingVisitor.Name = visitorEntity.Name;
existingVisitor.Phone = visitorEntity.Phone;
existingVisitor.Email = visitorEntity.Email;
existingVisitor.DayBirth = visitorEntity.DayBirth;
existingVisitor.Status = visitorEntity.Status;
existingVisitor.EventId = visitorEntity.EventId;
_context.SaveChanges();
return existingVisitor;
}
return null;
}
public bool Delete(int id)
{
var visitorEntity = _context.VisitorEntities.FirstOrDefault(v => v.Id == id);
if (visitorEntity != null)
{
_context.VisitorEntities.Remove(visitorEntity);
_context.SaveChanges();
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,34 @@
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.BindingModels
{
public class EventBindingModel: IEventModel
{
public int? Id { get; set; }
public string Name { get; set; } = string.Empty;
public DateTime Date { get; set; }
public DateTime TimeStart { get; set; }
public DateTime TimeEnd { get; set; }
public string Description { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string ContactPhone { get; set; } = string.Empty;
public string ContactEmail { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public int CountVisitors { get; set; }
public int FreePlaces { get; set; }
public Dictionary<int, IOrganizerModel> OrganizerEvent
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,26 @@
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.BindingModels
{
public class OrganizerBindingModel: IOrganizerModel
{
public int? Id { get; set; }
public string Surname { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string OrganizationName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public Dictionary<int, IEventModel> OrganizerEvent
{
get;
set;
} = new();
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EventVisitorModels\EventVisitorModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,21 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.StoragesContracts
{
public interface IEventStorage
{
List<EventViewModel> GetFullList();
// List<Event> GetFilteredList(Event model);
EventViewModel? GetElement(EventBindingModel model);
EventViewModel? Insert(EventBindingModel model);
EventViewModel? Update(EventBindingModel model);
EventViewModel? Delete(EventBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.StoragesContracts
{
public interface IOrganizerStorage
{
List<OrganizerViewModel> GetFullList();
// List<Organizer> GetFilteredList(Organizer model);
OrganizerViewModel? GetElement(OrganizerBindingModel model);
OrganizerViewModel? Insert(OrganizerBindingModel model);
OrganizerViewModel? Update(OrganizerBindingModel model);
OrganizerViewModel? Delete(OrganizerBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.StoragesContracts
{
public interface IVisitorStorage
{
List<IVisitorModel> GetFullList();
//List<Visitor> GetFilteredList(Visitor model);
IVisitorModel? GetElement(IVisitorModel model);
IVisitorModel? Insert(IVisitorModel model);
IVisitorModel? Update(IVisitorModel model);
IVisitorModel? Delete(IVisitorModel model);
}
}

View File

@ -0,0 +1,27 @@
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.ViewModels
{
public class EventViewModel: IEventModel
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public DateTime Date { get; set; }
public DateTime TimeStart { get; set; }
public DateTime TimeEnd { get; set; }
public string Description { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string ContactPhone { get; set; } = string.Empty;
public string ContactEmail { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public int CountVisitors { get; set; }
public int FreePlaces { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.ViewModels
{
public class OrganizerViewModel: IOrganizerModel
{
public int Id { get; set; }
public string Surname { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string OrganizationName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorModels
{
public class IEventModel
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public DateTime Date { get; set; }
public DateTime TimeStart { get; set; }
public DateTime TimeEnd { get; set; }
public string Description { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public string ContactPhone { get; set; } = string.Empty;
public string ContactEmail { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public int CountVisitors { get; set; }
public int FreePlaces { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorModels
{
public class IOrganizerModel
{
public int Id { get; set; }
public string Surname { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string OrganizationName { get; set; } = string.Empty;
public string Role { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorModels
{
public class IVisitorModel
{
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;
public DateTime DayBirth { get; set; }
public string Status { get; set; } = string.Empty;
public int EventId { get; set; }
}
}

View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace EventVisitorRestApi.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventVisitorDatabase\EventVisitorDatabase.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
@EventVisitorRestApi_HostAddress = http://localhost:5293
GET {{EventVisitorRestApi_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -0,0 +1,27 @@
using EventVisitorDatabase;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59165",
"sslPort": 44333
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5293",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7079;http://localhost:5293",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,13 @@
namespace EventVisitorRestApi
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}