ура бд готова

This commit is contained in:
EkaterinaR 2024-11-03 10:18:08 +04:00
parent b105074910
commit c219f9da5d
15 changed files with 812 additions and 58 deletions

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
@ -13,6 +13,14 @@
<ItemGroup>
<PackageReference Include="Font.Awesome" Version="5.15.4" />
<PackageReference Include="FontAwesome" Version="4.7.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
@ -27,4 +35,8 @@
<None Include="Pages\Events\EventRegister.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventVisitorDatabase\EventVisitorDatabase.csproj" />
</ItemGroup>
</Project>

View File

@ -1,7 +1,13 @@
using EventVisitorDatabase.Implements;
using EventVisitorLogic.StoragesContracts;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddTransient<IEventStorage, EventStorage>();
builder.Services.AddTransient<IVisitorStorage, VisitorStorage>();
builder.Services.AddTransient<IOrganizerStorage, OrganizerStorage>();
var app = builder.Build();

View File

@ -12,24 +12,35 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Xml.Linq;
using EventVisitorLogic.ViewModels;
using EventVisitorLogic.BindingModels;
using System.ComponentModel.DataAnnotations;
namespace EventVisitorDatabase.Entities
{
public class EventEntity
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public DateTime Date { get; set; }
[Required]
public DateTime TimeStart { get; set; }
public DateTime TimeEnd { get; set; }
public string Description { get; set; } = string.Empty;
[Required]
public string Type { get; set; } = string.Empty;
[Required]
public string ContactPhone { get; set; } = string.Empty;
public string ContactEmail { get; set; } = string.Empty;
[Required]
public string Address { get; set; } = string.Empty;
[Required]
public string City { get; set; } = string.Empty;
[Required]
public string Status { get; set; } = string.Empty;
[Required]
public int CountVisitors { get; set; }
[Required]
public int FreePlaces { get; set; }
[ForeignKey("EventId")]

View File

@ -9,17 +9,22 @@ using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System.ComponentModel.DataAnnotations;
namespace EventVisitorDatabase.Entities
{
public class OrganizerEntity
{
public int Id { get; set; }
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public string Name { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string OrganizationName { get; set; } = string.Empty;
[Required]
public string Role { get; set; } = string.Empty;
[Required]
public string Phone { get; set; } = string.Empty;
[ForeignKey("OrganizerId")]

View File

@ -1,7 +1,11 @@
using System;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace EventVisitorDatabase.Entities
@ -9,11 +13,65 @@ namespace EventVisitorDatabase.Entities
public class VisitorEntity
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
public DateTime DayBirth { get; set; }
[Required]
public string Status { get; set; } = string.Empty;
[Required]
public int EventId { get; set; }
public virtual EventEntity Event { get; set; }
public static VisitorEntity? Create(VisitorBindingModel model)
{
if (model == null)
{
return null;
}
return new VisitorEntity()
{
Id = (int)model.Id,
Name = model.Name,
Phone = model.Phone,
Email = model.Email,
DayBirth = model.DayBirth,
Status = model.Status,
EventId = model.EventId
};
}
public static VisitorEntity Create(VisitorViewModel model)
{
return new VisitorEntity
{
Id = model.Id,
Name = model.Name,
Phone = model.Phone,
Email = model.Email,
DayBirth = model.DayBirth,
Status = model.Status,
EventId = model.EventId
};
}
public void Update(VisitorBindingModel model)
{
if (model == null)
{
return;
}
Status = model.Status;
}
public VisitorViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Phone = Phone,
Email = Email,
DayBirth = DayBirth,
Status = Status,
EventId = EventId
};
}
}

View File

@ -8,6 +8,10 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup>

View File

@ -14,7 +14,7 @@ namespace EventVisitorDatabase
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<VisitorEntity> VisitorEntities { get; set; }
public virtual DbSet<VisitorEntity> Visitors { get; set; }
public virtual DbSet<OrganizerEntity> Organizers { get; set; }
public virtual DbSet<EventEntity> Events { get; set; }
public DbSet<OrganizerEvent> OrganizerEvent { get; set; }

View File

@ -1,71 +1,90 @@
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.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorDatabase.Implements
{
public class VisitorStorage
public class VisitorStorage: IVisitorStorage
{
private readonly EventVisitorDbContext _context;
public VisitorStorage(EventVisitorDbContext context)
public VisitorViewModel? Delete(VisitorBindingModel model)
{
_context = context;
}
public VisitorEntity? GetElement(int id)
using var context = new EventVisitorDbContext();
var element = context.Visitors.Include(x => x.Event).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
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;
context.Visitors.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public bool Delete(int id)
public VisitorViewModel? GetElement(VisitorBindingModel model)
{
var visitorEntity = _context.VisitorEntities.FirstOrDefault(v => v.Id == id);
if (visitorEntity != null)
if (!model.Id.HasValue)
{
_context.VisitorEntities.Remove(visitorEntity);
_context.SaveChanges();
return true;
return null;
}
using var context = new EventVisitorDbContext();
return context.Visitors.
Include(x => x.Event).
FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public List<VisitorViewModel> GetFullList()
{
using var context = new EventVisitorDbContext();
return context.Visitors.Include(x => x.Event)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public VisitorViewModel? Insert(VisitorBindingModel model)
{
using var context = new EventVisitorDbContext();
var newRecipe = VisitorEntity.Create(model);
if (newRecipe == null)
{
return null;
}
context.Visitors.Add(newRecipe);
context.SaveChanges();
return context.Visitors
.Include(x => x.Event)
.FirstOrDefault(x => x.Id == newRecipe.Id)?.GetViewModel;
}
public VisitorViewModel? Update(VisitorBindingModel model)
{
using var context = new EventVisitorDbContext();
using var transaction = context.Database.BeginTransaction();
try
{
var recipe = context.Visitors.FirstOrDefault(x => x.Id == model.Id);
if (recipe == null)
{
return null;
}
recipe.Update(model);
context.SaveChanges();
transaction.Commit();
return recipe.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
return false;
}
}
}

View File

@ -0,0 +1,227 @@
// <auto-generated />
using System;
using EventVisitorDatabase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace EventVisitorDatabase.Migrations
{
[DbContext(typeof(EventVisitorDbContext))]
[Migration("20241103061636_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("EventVisitorDatabase.Entities.EventEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<string>("City")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContactEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContactPhone")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CountVisitors")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<int>("FreePlaces")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("TimeEnd")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("TimeStart")
.HasColumnType("timestamp with time zone");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Events");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("OrganizationName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Organizers");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEvent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<int>("OrganizerId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("EventId");
b.HasIndex("OrganizerId");
b.ToTable("OrganizerEvent");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("DayBirth")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("EventId");
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")
.WithMany()
.HasForeignKey("EventId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
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
}
}
}

View File

@ -0,0 +1,140 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace EventVisitorDatabase.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Events",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
TimeStart = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
TimeEnd = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
Type = table.Column<string>(type: "text", nullable: false),
ContactPhone = table.Column<string>(type: "text", nullable: false),
ContactEmail = table.Column<string>(type: "text", nullable: false),
Address = table.Column<string>(type: "text", nullable: false),
City = table.Column<string>(type: "text", nullable: false),
Status = table.Column<string>(type: "text", nullable: false),
CountVisitors = table.Column<int>(type: "integer", nullable: false),
FreePlaces = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Events", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Organizers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Surname = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
LastName = table.Column<string>(type: "text", nullable: false),
OrganizationName = table.Column<string>(type: "text", nullable: false),
Role = table.Column<string>(type: "text", nullable: false),
Phone = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Organizers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Visitors",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Phone = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
DayBirth = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Status = table.Column<string>(type: "text", nullable: false),
EventId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Visitors", x => x.Id);
table.ForeignKey(
name: "FK_Visitors_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "OrganizerEvent",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
EventId = table.Column<int>(type: "integer", nullable: false),
OrganizerId = table.Column<int>(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",
column: "EventId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OrganizerEvent");
migrationBuilder.DropTable(
name: "Visitors");
migrationBuilder.DropTable(
name: "Organizers");
migrationBuilder.DropTable(
name: "Events");
}
}
}

View File

@ -0,0 +1,224 @@
// <auto-generated />
using System;
using EventVisitorDatabase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace EventVisitorDatabase.Migrations
{
[DbContext(typeof(EventVisitorDbContext))]
partial class EventVisitorDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("EventVisitorDatabase.Entities.EventEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<string>("City")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContactEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContactPhone")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CountVisitors")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<int>("FreePlaces")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("TimeEnd")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("TimeStart")
.HasColumnType("timestamp with time zone");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Events");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("OrganizationName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Organizers");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.OrganizerEvent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<int>("OrganizerId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("EventId");
b.HasIndex("OrganizerId");
b.ToTable("OrganizerEvent");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("DayBirth")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("EventId");
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")
.WithMany()
.HasForeignKey("EventId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
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
}
}
}

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.BindingModels
{
public class VisitorBindingModel: 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

@ -1,4 +1,6 @@
using EventVisitorModels;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using EventVisitorModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,11 +11,11 @@ namespace EventVisitorLogic.StoragesContracts
{
public interface IVisitorStorage
{
List<IVisitorModel> GetFullList();
List<VisitorViewModel> GetFullList();
//List<Visitor> GetFilteredList(Visitor model);
IVisitorModel? GetElement(IVisitorModel model);
IVisitorModel? Insert(IVisitorModel model);
IVisitorModel? Update(IVisitorModel model);
IVisitorModel? Delete(IVisitorModel model);
VisitorViewModel? GetElement(VisitorBindingModel model);
VisitorViewModel? Insert(VisitorBindingModel model);
VisitorViewModel? Update(VisitorBindingModel model);
VisitorViewModel? Delete(VisitorBindingModel model);
}
}

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 VisitorViewModel: 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

@ -1,4 +1,6 @@
using EventVisitorDatabase;
using EventVisitorDatabase.Implements;
using EventVisitorLogic.StoragesContracts;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
@ -9,6 +11,10 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddTransient<IEventStorage, EventStorage>();
builder.Services.AddTransient<IVisitorStorage, VisitorStorage>();
builder.Services.AddTransient<IOrganizerStorage, OrganizerStorage>();
var app = builder.Build();
// Configure the HTTP request pipeline.