Обновлена бд и настроена шапка

This commit is contained in:
EkaterinaR 2024-11-10 12:57:59 +04:00
parent d61ea1c163
commit 44cfe0a90b
17 changed files with 489 additions and 18 deletions

View File

@ -15,13 +15,14 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
using DocumentFormat.OpenXml.Office2010.Excel;
using System.Text;
using System.Security.Cryptography;
using DocumentFormat.OpenXml.Spreadsheet;
namespace EventVisitorClientApp.Controllers
{
public class HomeController : Controller
{
Random rnd = new Random();
private static readonly Random _random = new Random();
private void DisplayErrorMessage(string message)
{
ViewBag.ErrorMessage = message;
@ -119,9 +120,23 @@ namespace EventVisitorClientApp.Controllers
return View();
}
[HttpPost]
public void Register(string login, string password, string surname, string name, string lastname, string organizationName, string phone)
public static string GenerateRandomString()
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, 6)
.Select(s => s[_random.Next(s.Length)]).ToArray());
}
[HttpPost]
public void Register(string login, string password, string surname, string name, string lastname, string organizationName, string phone, string code)
{
//var confirmationCode = GenerateRandomString();
//APIClient.PostRequest("api/main/SendToMail", new MailSendInfoBindingModel
//{
// MailAddress = login,
// Subject = "Êîä äëÿ ïîäòâåðæäåíèÿ ðåãèñòðàöèè",
// Text = $"Âàø êîä äëÿ ïîäòâåðæäåíèÿ ðåãèñòðàöèè: {confirmationCode}"
//});
APIClient.PostRequest("api/Organizer/Register", new OrganizerBindingModel
{
Name = name,
@ -136,7 +151,25 @@ namespace EventVisitorClientApp.Controllers
return;
}
public IActionResult MyEvents()
[HttpPost]
public void CheckCode(string confirmationCode, string login, string password, string surname, string name, string lastname, string organizationName, string phone)
{
// Ïîëó÷àåì ñîõðàí¸ííûé êîä èç ñåññèè
var storedCode = HttpContext.Session.GetString("ConfirmationCode");
if (storedCode == confirmationCode)
{
}
else
{
// Îáðàáîòêà íåïðàâèëüíîãî êîäà, íàïðèìåð, îøèáêà 400
Response.StatusCode = 400;
return;
}
}
public IActionResult MyEvents()
{
if (APIClient.Client == null)
{

View File

@ -47,10 +47,11 @@
</div>
<div class="mb-4">
<button type="submit" class="btn btn-dark btn-lg w-100">Регистрация</button>
<button type="submit" class="btn btn-dark btn-lg w-100" data-bs-toggle="modal" data-bs-target="#confirmationModal">Регистрация</button>
</div>
</form>
</div>
<style>
.containerenter {
max-width: 500px;
@ -62,3 +63,4 @@
</style>

View File

@ -18,7 +18,7 @@
<label for="timestart" class="col-sm-4 col-form-label">Дата и время начала:</label>
<div class="col-sm-8">
<input type="datetime-local" class="form-control" id="timestart" name="timestart"
value="@Model.TimeStart.ToString("yyyy-MM-ddTHH:mm")" required>
value="@Model.TimeStart" required>
<div class="invalid-feedback">Пожалуйста, выберите дату и время начала.</div>
</div>
</div>
@ -26,7 +26,7 @@
<label for="timeend" class="col-sm-4 col-form-label">Дата и время конца:</label>
<div class="col-sm-8">
<input type="datetime-local" class="form-control" id="timeend" name="timeend"
value="@Model.TimeEnd.ToString("yyyy-MM-ddTHH:mm")" required>
value="@Model.TimeEnd" required>
<div class="invalid-feedback">Пожалуйста, выберите дату и время окончания.</div>
</div>
</div>

View File

@ -51,7 +51,23 @@
</form>
</div>
</div>
<a class="btn btn-dark btn-block mb-4" asp-action="RegistrationOnEvent" asp-route-id="@Model.Id">Страница с регистрацией</a>
@{
var isRegistrationClosed = Model.Status == "Регистрация закрыта";
var isEventFinished = Model.TimeEnd < DateTime.Now;
}
@if (!isRegistrationClosed && !isEventFinished)
{
<a class="btn btn-dark btn-block mb-4" asp-action="RegistrationOnEvent" asp-route-id="@Model.Id" target="_blank">Страница с регистрации</a>
}
else if (isRegistrationClosed)
{
<button class="btn btn-secondary btn-block mb-4" disabled>Регистрация закрыта</button>
}
else if (isEventFinished)
{
<button class="btn btn-secondary btn-block mb-4" disabled>Мероприятие уже прошло</button>
}
<a class="btn btn-dark btn-block mb-4" asp-action="Visitors" asp-route-id="@Model.Id">Посетители</a>
<a class="btn btn-dark btn-block mb-4" asp-action="ReportWord" asp-route-id="@Model.Id">Отчет Word о посетителях </a>
<a class="btn btn-dark btn-block mb-4" asp-action="ReportExcel" asp-route-id="@Model.Id">Отчет Excel о посетителях </a>

View File

@ -22,15 +22,28 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Главная</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="MyEvents">Moи мероприятия</a>
</li>
@if (APIClient.Client != null)
{
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="MyEvents">Мои мероприятия</a>
</li>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<form method="post" asp-area="" asp-controller="Account" asp-action="Logout" id="logoutForm" class="d-inline">
<button type="submit" class="nav-link btn btn-link text-dark">Выход</button>
</form>
</li>
</ul>
}
else
{
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
}
</ul>
</div>
</div>

View File

@ -0,0 +1,68 @@
using DocumentFormat.OpenXml.Wordprocessing;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
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 SentMessageEntity
{
public int Id { get; set; }
[Required]
public int OrganizerId { get; set; }
[Required]
public int EventId { get; set; }
[Required]
public string Subject { get; set; } = string.Empty;
[Required]
public string Body { get; set; } = string.Empty;
[Required]
public DateTime SentDate { get; set; }
public virtual OrganizerEntity Organizer { get; set; }
public virtual EventEntity Event { get; set; }
public static SentMessageEntity? Create(SentMessageBindingModel model)
{
if (model == null)
{
return null;
}
return new SentMessageEntity()
{
Id = model.Id,
OrganizerId = model.OrganizerId,
EventId = model.EventId,
Subject = model.Subject,
Body = model.Body,
SentDate = model.SentDate
};
}
public static SentMessageEntity Create(SentMessageViewModel model)
{
return new SentMessageEntity()
{
Id = model.Id,
OrganizerId = model.OrganizerId,
EventId = model.EventId,
Subject = model.Subject,
Body = model.Body,
SentDate = model.SentDate
};
}
public SentMessageViewModel GetViewModel => new()
{
Id = Id,
OrganizerId = OrganizerId,
EventId = EventId,
Subject = Subject,
Body = Body,
SentDate = SentDate
};
}
}

View File

@ -17,5 +17,6 @@ namespace EventVisitorDatabase
public virtual DbSet<VisitorEntity> Visitors { get; set; }
public virtual DbSet<OrganizerEntity> Organizers { get; set; }
public virtual DbSet<EventEntity> Events { get; set; }
public virtual DbSet<SentMessageEntity> SentMessages { get; set; }
}
}

View File

@ -0,0 +1,41 @@
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 SentMessageStorage : ISentMessageStorage
{
public List<SentMessageViewModel> GetFilteredList(SentMessageBindingModel model)
{
using var context = new EventVisitorDbContext();
return context.SentMessages
.Include(x => x.Event)
.Where(x => x.EventId == model.EventId).Select(x => x.GetViewModel).ToList();
}
public SentMessageViewModel? Insert(SentMessageBindingModel model)
{
using var context = new EventVisitorDbContext();
var newRecipe = SentMessageEntity.Create(model);
if (newRecipe == null)
{
return null;
}
context.SentMessages.Add(newRecipe);
context.SaveChanges();
return context.SentMessages
.Include(x => x.Event)
.Include(x => x.Organizer)
.FirstOrDefault(x => x.Id == newRecipe.Id)?.GetViewModel;
}
}
}

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace EventVisitorDatabase.Migrations
{
[DbContext(typeof(EventVisitorDbContext))]
[Migration("20241105194655_InitialCreate")]
[Migration("20241110074513_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -135,6 +135,40 @@ namespace EventVisitorDatabase.Migrations
b.ToTable("Organizers");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.SentMessageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<int>("OrganizerId")
.HasColumnType("integer");
b.Property<DateTime>("SentDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("EventId");
b.HasIndex("OrganizerId");
b.ToTable("SentMessages");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b =>
{
b.Property<int>("Id")
@ -183,6 +217,25 @@ namespace EventVisitorDatabase.Migrations
b.Navigation("Organizer");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.SentMessageEntity", b =>
{
b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event")
.WithMany()
.HasForeignKey("EventId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EventVisitorDatabase.Entities.OrganizerEntity", "Organizer")
.WithMany()
.HasForeignKey("OrganizerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Event");
b.Navigation("Organizer");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b =>
{
b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event")

View File

@ -64,6 +64,35 @@ namespace EventVisitorDatabase.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SentMessages",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OrganizerId = table.Column<int>(type: "integer", nullable: false),
EventId = table.Column<int>(type: "integer", nullable: false),
Subject = table.Column<string>(type: "text", nullable: false),
Body = table.Column<string>(type: "text", nullable: false),
SentDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SentMessages", x => x.Id);
table.ForeignKey(
name: "FK_SentMessages_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SentMessages_Organizers_OrganizerId",
column: x => x.OrganizerId,
principalTable: "Organizers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Visitors",
columns: table => new
@ -93,6 +122,16 @@ namespace EventVisitorDatabase.Migrations
table: "Events",
column: "OrganizerId");
migrationBuilder.CreateIndex(
name: "IX_SentMessages_EventId",
table: "SentMessages",
column: "EventId");
migrationBuilder.CreateIndex(
name: "IX_SentMessages_OrganizerId",
table: "SentMessages",
column: "OrganizerId");
migrationBuilder.CreateIndex(
name: "IX_Visitors_EventId",
table: "Visitors",
@ -102,6 +141,9 @@ namespace EventVisitorDatabase.Migrations
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SentMessages");
migrationBuilder.DropTable(
name: "Visitors");

View File

@ -132,6 +132,40 @@ namespace EventVisitorDatabase.Migrations
b.ToTable("Organizers");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.SentMessageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<int>("EventId")
.HasColumnType("integer");
b.Property<int>("OrganizerId")
.HasColumnType("integer");
b.Property<DateTime>("SentDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("EventId");
b.HasIndex("OrganizerId");
b.ToTable("SentMessages");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b =>
{
b.Property<int>("Id")
@ -180,6 +214,25 @@ namespace EventVisitorDatabase.Migrations
b.Navigation("Organizer");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.SentMessageEntity", b =>
{
b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event")
.WithMany()
.HasForeignKey("EventId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EventVisitorDatabase.Entities.OrganizerEntity", "Organizer")
.WithMany()
.HasForeignKey("OrganizerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Event");
b.Navigation("Organizer");
});
modelBuilder.Entity("EventVisitorDatabase.Entities.VisitorEntity", b =>
{
b.HasOne("EventVisitorDatabase.Entities.EventEntity", "Event")

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.BindingModels
{
public class SentMessageBindingModel: ISentMessageModel
{
public int Id { get; set; }
public int OrganizerId { get; set; }
public int EventId { get; set; }
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public DateTime SentDate { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.Logic
{
public interface ISentMessageLogic
{
List<SentMessageViewModel>? ReadList(SentMessageBindingModel? model);
bool Create(SentMessageBindingModel model);
}
}

View File

@ -0,0 +1,61 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.StoragesContracts;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.Logic
{
public class SentMessageLogic : ISentMessageLogic
{
private readonly ISentMessageStorage _messageStorage;
public SentMessageLogic(ISentMessageStorage messageStorage)
{
_messageStorage = messageStorage;
}
public bool Create(SentMessageBindingModel model)
{
CheckModel(model);
var result = _messageStorage.Insert(model);
if (result == null)
{
return false;
}
return true;
}
public List<SentMessageViewModel>? ReadList(SentMessageBindingModel? model)
{
var list = _messageStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
private void CheckModel(SentMessageBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Subject))
{
throw new ArgumentNullException("Нет темы сообщения", nameof(model.Subject));
}
if (string.IsNullOrEmpty(model.Body))
{
throw new ArgumentNullException("Нет текста сообщения", nameof(model.Body));
}
}
}
}

View File

@ -0,0 +1,16 @@
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorLogic.StoragesContracts
{
public interface ISentMessageStorage
{
List<SentMessageViewModel> GetFilteredList(SentMessageBindingModel model);
SentMessageViewModel? Insert(SentMessageBindingModel 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.ViewModels
{
public class SentMessageViewModel: ISentMessageModel
{
public int Id { get; set; }
public int OrganizerId { get; set; }
public int EventId { get; set; }
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public DateTime SentDate { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorModels
{
public class ISentMessageModel
{
public int Id { get; set; }
public int OrganizerId { get; set; }
public int EventId { get; set; }
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public DateTime SentDate { get; set; }
}
}