This commit is contained in:
AnnZhimol 2023-05-16 17:42:19 +04:00
commit 948c454c30
22 changed files with 600 additions and 103 deletions

View File

@ -1,4 +1,6 @@
using HostrelHeadwaiterApp.Models; using HostrelHeadwaiterApp.Models;
using HotelContracts.BindingModels;
using HotelContracts.ViewModels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Diagnostics; using System.Diagnostics;
@ -13,57 +15,218 @@ namespace HostrelHeadwaiterApp.Controllers
_logger = logger; _logger = logger;
} }
public IActionResult CreateDinner()
{
if (APIClient.Headwaiter == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public void CreateDinner(double dinnerPrice, string dinnerName)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(dinnerName))
{
throw new Exception("Введите имя");
}
APIClient.PostRequest("api/main/createdinner", new DinnerBindingModel
{
DinnerPrice = dinnerPrice,
DinnerName = dinnerName,
HeadwaiterId = APIClient.Headwaiter.Id,
});
Response.Redirect("ListDinners");
}
public IActionResult UpdateDinner()
{
if (APIClient.Headwaiter == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Dinners = APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}");
return View();
}
[HttpPost]
public void UpdateDinner(int dinner, string dinnerName, double dinnerPrice)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Необходима авторизация");
}
if (string.IsNullOrEmpty(dinnerName))
{
throw new Exception("имя не может быть пустым");
}
APIClient.PostRequest("api/main/updatedinner", new DinnerBindingModel
{
Id = dinner,
DinnerName = dinnerName,
DinnerPrice = dinnerPrice,
HeadwaiterId = APIClient.Headwaiter.Id,
});
Response.Redirect("ListDinners");
}
public IActionResult DeleteDinner()
{
if (APIClient.Headwaiter == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Dinners = APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}");
return View();
}
[HttpPost]
public void DeleteDinner(int dinner)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Необходима авторизация");
}
APIClient.PostRequest("api/main/deletedinner", new DinnerBindingModel
{
Id = dinner
});
Response.Redirect("ListDinners");
}
[HttpGet]
public DinnerViewModel? GetDinner(int dinnerId)
{
if (APIClient.Headwaiter == null)
{
throw new Exception("Необходима авторизация");
}
var result = APIClient.GetRequest<DinnerViewModel>($"api/main/getdinner?dinnerid={dinnerId}");
if (result == null)
{
return default;
}
var dinnerPrice = result.DinnerPrice;
var dinnerName = result.DinnerName;
return result;
}
public IActionResult Index() public IActionResult Index()
{ {
return View(); if (APIClient.Headwaiter == null)
}
public IActionResult Register()
{ {
return Redirect("~/Home/Enter");
}
return View(); return View();
} }
public IActionResult Enter() public IActionResult ListDinners()
{ {
return View(); if (APIClient.Headwaiter == null)
}
public IActionResult Report()
{ {
return View(); return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}"));
} }
public IActionResult BindingConferenceBindingAndConference() [HttpGet]
public IActionResult Privacy()
{ {
return View(); if (APIClient.Headwaiter == null)
}
public IActionResult FormationDinner()
{ {
return View(); return Redirect("~/Home/Enter");
}
return View(APIClient.Headwaiter);
} }
public IActionResult ShapingDinnerIntoRooms() [HttpPost]
public void Privacy(string login, string email, string password, string fio, string telephone)
{ {
return View(); if (APIClient.Headwaiter == null)
}
public IActionResult FormationOfDinnerInConferenceBookings()
{ {
return View(); throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
} }
public IActionResult ListOfMealPlans() if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{ {
return View(); throw new Exception("Введите логин, пароль и ФИО");
} }
APIClient.PostRequest("api/headwaiter/updatedata", new HeadwaiterBindingModel
{
Id = APIClient.Headwaiter.Id,
HeadwaiterFIO = fio,
HeadwaiterLogin = login,
HeadwaiterPassword = password,
HeadwaiterEmail = email,
HeadwaiterNumber = telephone
});
APIClient.Headwaiter.HeadwaiterFIO = fio;
APIClient.Headwaiter.HeadwaiterLogin = login;
APIClient.Headwaiter.HeadwaiterPassword = password;
APIClient.Headwaiter.HeadwaiterEmail = email;
APIClient.Headwaiter.HeadwaiterNumber = telephone;
Response.Redirect("Index");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIClient.Headwaiter = APIClient.GetRequest<HeadwaiterViewModel>($"api/headwaiter/login?login={login}&password={password}");
if (APIClient.Headwaiter == null)
{
throw new Exception("Неверный логин/пароль");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string email, string password, string fio, string telephone)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/headwaiter/register", new HeadwaiterBindingModel
{
HeadwaiterFIO = fio,
HeadwaiterLogin = login,
HeadwaiterPassword = password,
HeadwaiterEmail = email,
HeadwaiterNumber = telephone
});
Response.Redirect("Enter");
return;
}
} }
} }

View File

@ -1,9 +1,12 @@
using HostrelHeadwaiterApp;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())

View File

@ -1,21 +1,35 @@
@{ @{
ViewData["Title"] = "Enter"; ViewData["Title"] = "Enter";
} }
<head>
<link rel="stylesheet" href="~/css/entry.css" asp-append-version="true" />
</head>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Вход в приложение</h2> <h2
class="u-text u-text-custom-color-1 u-text-default u-text-1"
>
Вход
</h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="u-form-group u-label-top u-form-group-1">
<div class="col-4">Логин:</div> <label class="u-label u-text-custom-color-1 u-label-1">Электронная почта</label>
<div class="col-8"><input type="text" name="login" /></div> <input
type="text"
placeholder="Введите свой логин"
name="login"
class="u-input u-input-rectangle u-input-1"/>
</div> </div>
<div class="row"> <div class="u-form-group u-label-top u-form-group-2">
<div class="col-4">Пароль:</div> <label class="u-label u-text-custom-color-1 u-label-2">Пароль</label>
<div class="col-8"><input type="password" name="password" /></div> <input
type="password"
placeholder="Введите свой пароль"
name="password"
class="u-input u-input-rectangle u-input-2"/>
</div> </div>
<div class="row"> <div class="u-align-center u-form-group u-form-submit u-label-top">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Войти" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1"/></div>
</div> </div>
</form> </form>

View File

@ -7,17 +7,44 @@
ViewData["Title"] = "Home Page"; ViewData["Title"] = "Home Page";
} }
<div class="text-center"> <head>
<h1 class="display-4">Заказы</h1> <link rel="stylesheet" href="~/css/mainpage.css" asp-append-version="true" />
</head>
<section class="u-clearfix u-section-1" id="sec-83a8">
<div class="u-clearfix u-sheet u-sheet-1">
<div class="u-clearfix u-expanded-width u-layout-wrap u-layout-wrap-1">
<div class="u-layout">
<div class="u-layout-col">
<div
class="u-container-style u-layout-cell u-size-30 u-layout-cell-1"
>
<div
class="u-container-layout u-valign-bottom u-container-layout-1"
>
<h2
class="u-align-center u-text u-text-custom-color-1 u-text-default u-text-1"
>
Гостиница
</h2>
</div> </div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
}
</div> </div>
<div
class="u-container-style u-layout-cell u-size-30 u-layout-cell-2"
>
<div
class="u-container-layout u-valign-top u-container-layout-2"
style="padding: 120px"
>
<img
class="u-image u-image-contain u-image-1"
src="~/Images/logo.png"
data-image-width="2388"
data-image-height="1260"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</section>

View File

@ -1,33 +1,56 @@
@{ @{
ViewData["Title"] = "Register"; ViewData["Title"] = "Register";
} }
<head>
<link rel="stylesheet" href="~/css/register.css" asp-append-version="true" />
</head>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Регистрация</h2> <h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Регистрация </h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="u-form-group u-form-name u-label-top">
<div class="col-4">ФИО:</div> <label class="u-label u-text-custom-color-1 u-label-1">Логин</label>
<div class="col-8"><input type="text" name="fio" /></div> <input
type="text"
placeholder="Введите логин"
name="login"
class="u-input u-input-rectangle"/>
</div> </div>
<div class="row"> <div class="u-form-email u-form-group u-label-top">
<div class="col-4">Логин:</div> <label class="u-label u-text-custom-color-1 u-label-2">Электронная почта</label>
<div class="col-8"><input type="text" name="login" /></div> <input
type="email"
placeholder="Введите электронную почту"
name="email"
class="u-input u-input-rectangle"/>
</div> </div>
<div class="row"> <div class="u-form-group u-label-top u-form-group-3">
<div class="col-4">Пароль:</div> <label class="u-label u-text-custom-color-1 u-label-3">ФИО</label>
<div class="col-8"><input type="password" name="password" /></div> <input
type="text"
placeholder="Введите ФИО"
name="fio"
class="u-input u-input-rectangle"/>
</div> </div>
<div class="row"> <div class="u-form-group u-label-top u-form-group-4">
<div class="col-4">Электронная почта:</div> <label class="u-label u-text-custom-color-1 u-label-4">Номер телефона</label>
<div class="col-8"><input type="text" name="email" /></div> <input
type="text"
name="telephone"
class="u-input u-input-rectangle"
placeholder="Введите номер телефона"/>
</div> </div>
<div class="row"> <div class="u-form-group u-label-top u-form-group-5">
<div class="col-4">Номер телефона:</div> <label class="u-label u-text-custom-color-1 u-label-5">Пароль</label>
<div class="col-8"><input type="text" name="telephone" /></div> <input
type="password"
placeholder="Введите пароль"
name="password"
class="u-input u-input-rectangle"/>
</div> </div>
<div class="row"> <div class="u-align-center u-form-group u-form-submit u-label-top"
style="padding: 120px">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Зарегистрироваться" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
</div> </div>
</form> </form>

View File

@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"IPAddress": "http://localhost:5079/"
} }

View File

@ -5,6 +5,7 @@ namespace HotelContracts.SearchModels
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? HeadwaiterId { get; set; } public int? HeadwaiterId { get; set; }
public int? ConferenceId { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
} }

View File

@ -4,6 +4,7 @@ namespace HotelContracts.SearchModels
public class DinnerSearchModel public class DinnerSearchModel
{ {
public string? DinnerName { get; set; } public string? DinnerName { get; set; }
public int? HeadwaiterId { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
} }
} }

View File

@ -6,7 +6,7 @@ namespace HotelContracts.SearchModels
public string? HeadwaiterFIO { get; set; } public string? HeadwaiterFIO { get; set; }
public string? HeadwaiterPassword { get; set; } public string? HeadwaiterPassword { get; set; }
public string? HeadwaiterEmail { get; set; }
public string? HeadwaiterLogin { get; set; } public string? HeadwaiterLogin { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
} }

View File

@ -4,6 +4,8 @@ namespace HotelContracts.SearchModels
public class RoomSearchModel public class RoomSearchModel
{ {
public string? RoomName { get; set; } public string? RoomName { get; set; }
public int? HeadwaiterId { get; set; }
public int? MealPlanId { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
} }
} }

View File

@ -9,7 +9,7 @@ namespace HotelDataBaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-VG5USAH\SQLEXPRESS;Initial Catalog=HotelDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-V0ON61E\SQLEXPRESS;Initial Catalog=HotelDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -51,13 +51,26 @@ namespace HotelDataBaseImplement.Implemets
public List<DinnerViewModel> GetFilteredList(DinnerSearchModel model) public List<DinnerViewModel> GetFilteredList(DinnerSearchModel model)
{ {
if (string.IsNullOrEmpty(model.DinnerName)) if (string.IsNullOrEmpty(model.DinnerName) && !model.HeadwaiterId.HasValue)
{ {
return new(); return new();
} }
using var context = new HotelDataBase(); using var context = new HotelDataBase();
if (model.HeadwaiterId.HasValue)
{
return context.Dinners
.Include(x => x.RoomDinners)
.ThenInclude(x => x.Room)
.Include(x => x.ConferenceBookingDinners)
.ThenInclude(x => x.ConferenceBooking)
.Where(x => x.DinnerName.Contains(model.DinnerName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.Dinners return context.Dinners
.Include(x => x.RoomDinners) .Include(x => x.RoomDinners)
.ThenInclude(x => x.Room) .ThenInclude(x => x.Room)

View File

@ -43,20 +43,20 @@ namespace HotelDataBaseImplement.Implemets
.FirstOrDefault(x => x.Id == model.Id)? .FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel; .GetViewModel;
if (!string.IsNullOrEmpty(model.HeadwaiterLogin) && !string.IsNullOrEmpty(model.HeadwaiterPassword)) if (!string.IsNullOrEmpty(model.HeadwaiterEmail) && !string.IsNullOrEmpty(model.HeadwaiterPassword))
return context.Headwaiters return context.Headwaiters
.Include(x => x.ConferenceBookings) .Include(x => x.ConferenceBookings)
.Include(x => x.Dinners) .Include(x => x.Dinners)
.Include(x => x.Rooms) .Include(x => x.Rooms)
.FirstOrDefault(x => x.HeadwaiterLogin.Equals(model.HeadwaiterLogin) && x.HeadwaiterPassword.Equals(model.HeadwaiterPassword))? .FirstOrDefault(x => x.HeadwaiterEmail.Equals(model.HeadwaiterEmail) && x.HeadwaiterPassword.Equals(model.HeadwaiterPassword))?
.GetViewModel; .GetViewModel;
if (!string.IsNullOrEmpty(model.HeadwaiterLogin)) if (!string.IsNullOrEmpty(model.HeadwaiterEmail))
return context.Headwaiters return context.Headwaiters
.Include(x => x.ConferenceBookings) .Include(x => x.ConferenceBookings)
.Include(x => x.Dinners) .Include(x => x.Dinners)
.Include(x => x.Rooms) .Include(x => x.Rooms)
.FirstOrDefault(x => x.HeadwaiterLogin.Equals(model.HeadwaiterLogin))? .FirstOrDefault(x => x.HeadwaiterEmail.Equals(model.HeadwaiterEmail))?
.GetViewModel; .GetViewModel;
return null; return null;

View File

@ -34,13 +34,26 @@ namespace HotelDataBaseImplement.Implemets
public RoomViewModel? GetElement(RoomSearchModel model) public RoomViewModel? GetElement(RoomSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && !model.HeadwaiterId.HasValue)
{ {
return null; return null;
} }
using var context = new HotelDataBase(); using var context = new HotelDataBase();
if (model.HeadwaiterId.HasValue)
{
return context.Rooms
.Include(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.ThenInclude(x => x.ConferenceBookingDinners)
.ThenInclude(x => x.ConferenceBooking)
.Include(x => x.MealPlan)
.Include(x => x.Headwaiter)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
return context.Rooms return context.Rooms
.Include(x => x.Dinners) .Include(x => x.Dinners)
.ThenInclude(x => x.Dinner) .ThenInclude(x => x.Dinner)

View File

@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace HotelDataBaseImplement.Migrations namespace HotelDataBaseImplement.Migrations
{ {
[DbContext(typeof(HotelDataBase))] [DbContext(typeof(HotelDataBase))]
[Migration("20230405210621_InitialCreate")] [Migration("20230515204810_coursework")]
partial class InitialCreate partial class coursework
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -137,7 +137,7 @@ namespace HotelDataBaseImplement.Migrations
.IsRequired() .IsRequired()
.HasColumnType("nvarchar(max)"); .HasColumnType("nvarchar(max)");
b.Property<double>("DinnetPrice") b.Property<double>("DinnerPrice")
.HasColumnType("float"); .HasColumnType("float");
b.Property<int>("HeadwaiterId") b.Property<int>("HeadwaiterId")

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace HotelDataBaseImplement.Migrations namespace HotelDataBaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitialCreate : Migration public partial class coursework : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -53,7 +53,7 @@ namespace HotelDataBaseImplement.Migrations
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
HeadwaiterId = table.Column<int>(type: "int", nullable: false), HeadwaiterId = table.Column<int>(type: "int", nullable: false),
DinnerName = table.Column<string>(type: "nvarchar(max)", nullable: false), DinnerName = table.Column<string>(type: "nvarchar(max)", nullable: false),
DinnetPrice = table.Column<double>(type: "float", nullable: false) DinnerPrice = table.Column<double>(type: "float", nullable: false)
}, },
constraints: table => constraints: table =>
{ {

View File

@ -40,6 +40,8 @@ namespace HotelDataBaseImplement.Models
return new ConferenceBooking() return new ConferenceBooking()
{ {
Id = model.Id, Id = model.Id,
ConferenceId = model.ConferenceId,
HeadwaiterId = model.HeadwaiterId,
Dinners = model.ConferenceBookingDinners.Select(x => new ConferenceBookingDinner Dinners = model.ConferenceBookingDinners.Select(x => new ConferenceBookingDinner
{ {
Dinner = context.Dinners.First(y => y.Id == x.Key), Dinner = context.Dinners.First(y => y.Id == x.Key),
@ -49,12 +51,15 @@ namespace HotelDataBaseImplement.Models
public void Update(ConferenceBookingBindingModel model) public void Update(ConferenceBookingBindingModel model)
{ {
ConferenceId = model.ConferenceId;
HeadwaiterId = model.HeadwaiterId;
} }
public ConferenceBookingViewModel GetViewModel => new() public ConferenceBookingViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
ConferenceId = ConferenceId,
HeadwaiterId = HeadwaiterId,
ConferenceBookingDinners = ConferenceBookingDinners ConferenceBookingDinners = ConferenceBookingDinners
}; };

View File

@ -39,6 +39,7 @@ namespace HotelDataBaseImplement.Models
{ {
Id = model.Id, Id = model.Id,
DinnerName = model.DinnerName, DinnerName = model.DinnerName,
HeadwaiterId = model.HeadwaiterId,
DinnerPrice = model.DinnerPrice DinnerPrice = model.DinnerPrice
}; };
} }
@ -48,6 +49,7 @@ namespace HotelDataBaseImplement.Models
{ {
Id = model.Id, Id = model.Id,
DinnerName = model.DinnerName, DinnerName = model.DinnerName,
HeadwaiterId = model.HeadwaiterId,
DinnerPrice = model.DinnerPrice DinnerPrice = model.DinnerPrice
}; };
} }
@ -57,6 +59,7 @@ namespace HotelDataBaseImplement.Models
{ {
return; return;
} }
HeadwaiterId = model.HeadwaiterId;
DinnerName = model.DinnerName; DinnerName = model.DinnerName;
DinnerPrice = model.DinnerPrice; DinnerPrice = model.DinnerPrice;
} }
@ -64,6 +67,7 @@ namespace HotelDataBaseImplement.Models
{ {
Id = Id, Id = Id,
DinnerName = DinnerName, DinnerName = DinnerName,
HeadwaiterId = HeadwaiterId,
DinnerPrice = DinnerPrice DinnerPrice = DinnerPrice
}; };
} }

View File

@ -50,6 +50,8 @@ namespace HotelDataBaseImplement.Models
RoomName = model.RoomName, RoomName = model.RoomName,
RoomFrame = model.RoomFrame, RoomFrame = model.RoomFrame,
RoomPrice = model.RoomPrice, RoomPrice = model.RoomPrice,
HeadwaiterId = model.HeadwaiterId,
MealPlanId = model.MealPlanId,
Dinners = model.RoomDinners.Select(x => new RoomDinner Dinners = model.RoomDinners.Select(x => new RoomDinner
{ {
Dinner = context.Dinners.First(y => y.Id == x.Key), Dinner = context.Dinners.First(y => y.Id == x.Key),
@ -62,6 +64,8 @@ namespace HotelDataBaseImplement.Models
RoomName = model.RoomName; RoomName = model.RoomName;
RoomFrame = model.RoomFrame; RoomFrame = model.RoomFrame;
RoomPrice = model.RoomPrice; RoomPrice = model.RoomPrice;
HeadwaiterId = model.HeadwaiterId;
MealPlanId = model.MealPlanId;
} }
public RoomViewModel GetViewModel => new() public RoomViewModel GetViewModel => new()
@ -69,6 +73,8 @@ namespace HotelDataBaseImplement.Models
Id = Id, Id = Id,
RoomName = RoomName, RoomName = RoomName,
RoomFrame = RoomFrame, RoomFrame = RoomFrame,
HeadwaiterId = HeadwaiterId,
MealPlanId = MealPlanId,
RoomPrice = RoomPrice, RoomPrice = RoomPrice,
RoomDinners = RoomDinners RoomDinners = RoomDinners
}; };

View File

@ -0,0 +1,67 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace HotelRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class HeadwaiterController : Controller
{
private readonly ILogger _logger;
private readonly IHeadwaiterLogic _logic;
public HeadwaiterController(IHeadwaiterLogic logic, ILogger<HeadwaiterController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public HeadwaiterViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new HeadwaiterSearchModel
{
HeadwaiterEmail = login,
HeadwaiterPassword = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(HeadwaiterBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(HeadwaiterBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}

View File

@ -17,13 +17,19 @@ namespace HotelRestApi.Controllers
private readonly IConferenceLogic _conference; private readonly IConferenceLogic _conference;
private readonly IMemberLogic _member; private readonly IMemberLogic _member;
private readonly IMealPlanLogic _mealPlan; private readonly IMealPlanLogic _mealPlan;
private readonly IDinnerLogic _dinner;
private readonly IConferenceBookingLogic _conferenceBooking;
private readonly IRoomLogic _room;
public MainController(ILogger<MainController> logger, IConferenceLogic conference, IMemberLogic member, IMealPlanLogic mealPlan) public MainController(ILogger<MainController> logger, IConferenceLogic conference, IMemberLogic member, IMealPlanLogic mealPlan, IDinnerLogic dinner, IConferenceBookingLogic conferenceBooking, IRoomLogic room)
{ {
_logger = logger; _logger = logger;
_conference = conference; _conference = conference;
_member = member; _member = member;
_mealPlan = mealPlan; _mealPlan = mealPlan;
_dinner = dinner;
_conferenceBooking = conferenceBooking;
_room = room;
} }
[HttpGet] [HttpGet]
@ -77,6 +83,57 @@ namespace HotelRestApi.Controllers
} }
} }
[HttpGet]
public List<DinnerViewModel>? GetDinnerList(int headwaiterId)
{
try
{
return _dinner.ReadList(new DinnerSearchModel
{
HeadwaiterId = headwaiterId,
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка обедов");
throw;
}
}
[HttpGet]
public List<ConferenceBookingViewModel>? GetConferenceBookingList(int headwaiterId)
{
try
{
return _conferenceBooking.ReadList(new ConferenceBookingSearchModel
{
HeadwaiterId = headwaiterId,
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка бронирования по конференциям");
throw;
}
}
[HttpGet]
public List<RoomViewModel>? GetRoomPlanList(int headwaiterId)
{
try
{
return _room.ReadList(new RoomSearchModel
{
HeadwaiterId = headwaiterId,
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка номеров");
throw;
}
}
[HttpPost] [HttpPost]
public void UpdateMember(MemberBindingModel model) public void UpdateMember(MemberBindingModel model)
{ {
@ -136,6 +193,65 @@ namespace HotelRestApi.Controllers
} }
} }
[HttpPost]
public void UpdateDinner(DinnerBindingModel model)
{
try
{
_dinner.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных обеда");
throw;
}
}
[HttpGet]
public DinnerViewModel? GetDinner(int dinnerId)
{
try
{
return _dinner.ReadElement(new DinnerSearchModel
{
Id = dinnerId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения обеда по id={Id}", dinnerId);
throw;
}
}
[HttpPost]
public void CreateDinner(DinnerBindingModel model)
{
try
{
_dinner.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания обеда");
throw;
}
}
[HttpPost]
public void DeleteDinner(DinnerBindingModel model)
{
try
{
_dinner.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления обеда");
throw;
}
}
[HttpPost] [HttpPost]
public void CreateConference(ConferenceBindingModel model) public void CreateConference(ConferenceBindingModel model)
{ {
@ -223,5 +339,33 @@ namespace HotelRestApi.Controllers
throw; throw;
} }
} }
[HttpPost]
public void CreateRoom(RoomBindingModel model)
{
try
{
_room.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания комнаты");
throw;
}
}
[HttpPost]
public void CreateConferenceBooking(ConferenceBookingBindingModel model)
{
try
{
_conferenceBooking.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания бронирования конференций");
throw;
}
}
} }
} }

View File

@ -22,6 +22,16 @@ builder.Services.AddTransient<IMealPlanLogic, MealPlanLogic>();
builder.Services.AddTransient<IMemberLogic, MemberLogic>(); builder.Services.AddTransient<IMemberLogic, MemberLogic>();
builder.Services.AddTransient<IConferenceLogic, ConferenceLogic>(); builder.Services.AddTransient<IConferenceLogic, ConferenceLogic>();
builder.Services.AddTransient<IHeadwaiterStorage, HeadwaiterStorage>();
builder.Services.AddTransient<IDinnerStorage, DinnerStorage>();
builder.Services.AddTransient<IRoomStorage, RoomStorage>();
builder.Services.AddTransient<IConferenceBookingStorage, ConferenceBookingStorage>();
builder.Services.AddTransient<IHeadwaiterLogic, HeadwaiterLogic>();
builder.Services.AddTransient<IDinnerLogic, DinnerLogic>();
builder.Services.AddTransient<IRoomLogic, RoomLogic>();
builder.Services.AddTransient<IConferenceBookingLogic, ConferenceBookingLogic>();
//builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>(); //builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddControllers(); builder.Services.AddControllers();