Merge branch 'CourseWork' of http://student.git.athene.tech/AnnZhimol/CourseWork_Hotel into CourseWork
This commit is contained in:
commit
948c454c30
@ -1,4 +1,6 @@
|
||||
using HostrelHeadwaiterApp.Models;
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
@ -13,57 +15,218 @@ namespace HostrelHeadwaiterApp.Controllers
|
||||
_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()
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Register()
|
||||
public IActionResult ListDinners()
|
||||
{
|
||||
return View();
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<DinnerViewModel>>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.Headwaiter);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Privacy(string login, string email, string password, string fio, string telephone)
|
||||
{
|
||||
if (APIClient.Headwaiter == null)
|
||||
{
|
||||
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
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)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Report()
|
||||
[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();
|
||||
}
|
||||
|
||||
public IActionResult BindingConferenceBindingAndConference()
|
||||
[HttpPost]
|
||||
public void Register(string login, string email, string password, string fio, string telephone)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
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
|
||||
});
|
||||
|
||||
public IActionResult FormationDinner()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult ShapingDinnerIntoRooms()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult FormationOfDinnerInConferenceBookings()
|
||||
{
|
||||
return View();
|
||||
|
||||
}
|
||||
public IActionResult ListOfMealPlans()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using HostrelHeadwaiterApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
|
@ -1,21 +1,35 @@
|
||||
@{
|
||||
ViewData["Title"] = "Enter";
|
||||
}
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="~/css/entry.css" asp-append-version="true" />
|
||||
</head>
|
||||
<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>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<div class="u-form-group u-label-top u-form-group-1">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Электронная почта</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Введите свой логин"
|
||||
name="login"
|
||||
class="u-input u-input-rectangle u-input-1"/>
|
||||
</div>
|
||||
<div class="u-form-group u-label-top u-form-group-2">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Пароль</label>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Введите свой пароль"
|
||||
name="password"
|
||||
class="u-input u-input-rectangle u-input-2"/>
|
||||
</div>
|
||||
<div class="u-align-center u-form-group u-form-submit u-label-top">
|
||||
<div class="col-8"></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>
|
||||
</form>
|
@ -7,17 +7,44 @@
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Заказы</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<head>
|
||||
<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="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>
|
@ -1,33 +1,56 @@
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="~/css/register.css" asp-append-version="true" />
|
||||
</head>
|
||||
<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>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">ФИО:</div>
|
||||
<div class="col-8"><input type="text" name="fio" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
<div class="col-8"><input type="password" name="password" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Электронная почта:</div>
|
||||
<div class="col-8"><input type="text" name="email" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Номер телефона:</div>
|
||||
<div class="col-8"><input type="text" name="telephone" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="u-form-group u-form-name u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-1">Логин</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Введите логин"
|
||||
name="login"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-form-email u-form-group u-label-top">
|
||||
<label class="u-label u-text-custom-color-1 u-label-2">Электронная почта</label>
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Введите электронную почту"
|
||||
name="email"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-form-group u-label-top u-form-group-3">
|
||||
<label class="u-label u-text-custom-color-1 u-label-3">ФИО</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Введите ФИО"
|
||||
name="fio"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<div class="u-form-group u-label-top u-form-group-4">
|
||||
<label class="u-label u-text-custom-color-1 u-label-4">Номер телефона</label>
|
||||
<input
|
||||
type="text"
|
||||
name="telephone"
|
||||
class="u-input u-input-rectangle"
|
||||
placeholder="Введите номер телефона"/>
|
||||
</div>
|
||||
<div class="u-form-group u-label-top u-form-group-5">
|
||||
<label class="u-label u-text-custom-color-1 u-label-5">Пароль</label>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Введите пароль"
|
||||
name="password"
|
||||
class="u-input u-input-rectangle"/>
|
||||
</div>
|
||||
<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-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>
|
||||
</form>
|
@ -5,5 +5,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"IPAddress": "http://localhost:5079/"
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace HotelContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? HeadwaiterId { get; set; }
|
||||
public int? ConferenceId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace HotelContracts.SearchModels
|
||||
public class DinnerSearchModel
|
||||
{
|
||||
public string? DinnerName { get; set; }
|
||||
public int? HeadwaiterId { get; set; }
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace HotelContracts.SearchModels
|
||||
public string? HeadwaiterFIO { get; set; }
|
||||
|
||||
public string? HeadwaiterPassword { get; set; }
|
||||
|
||||
public string? HeadwaiterEmail { get; set; }
|
||||
public string? HeadwaiterLogin { get; set; }
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ namespace HotelContracts.SearchModels
|
||||
public class RoomSearchModel
|
||||
{
|
||||
public string? RoomName { get; set; }
|
||||
public int? HeadwaiterId { get; set; }
|
||||
public int? MealPlanId { get; set; }
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace HotelDataBaseImplement
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -51,13 +51,26 @@ namespace HotelDataBaseImplement.Implemets
|
||||
|
||||
public List<DinnerViewModel> GetFilteredList(DinnerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DinnerName))
|
||||
if (string.IsNullOrEmpty(model.DinnerName) && !model.HeadwaiterId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
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
|
||||
.Include(x => x.RoomDinners)
|
||||
.ThenInclude(x => x.Room)
|
||||
|
@ -43,20 +43,20 @@ namespace HotelDataBaseImplement.Implemets
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.HeadwaiterLogin) && !string.IsNullOrEmpty(model.HeadwaiterPassword))
|
||||
if (!string.IsNullOrEmpty(model.HeadwaiterEmail) && !string.IsNullOrEmpty(model.HeadwaiterPassword))
|
||||
return context.Headwaiters
|
||||
.Include(x => x.ConferenceBookings)
|
||||
.Include(x => x.Dinners)
|
||||
.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;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.HeadwaiterLogin))
|
||||
if (!string.IsNullOrEmpty(model.HeadwaiterEmail))
|
||||
return context.Headwaiters
|
||||
.Include(x => x.ConferenceBookings)
|
||||
.Include(x => x.Dinners)
|
||||
.Include(x => x.Rooms)
|
||||
.FirstOrDefault(x => x.HeadwaiterLogin.Equals(model.HeadwaiterLogin))?
|
||||
.FirstOrDefault(x => x.HeadwaiterEmail.Equals(model.HeadwaiterEmail))?
|
||||
.GetViewModel;
|
||||
|
||||
return null;
|
||||
|
@ -34,13 +34,26 @@ namespace HotelDataBaseImplement.Implemets
|
||||
|
||||
public RoomViewModel? GetElement(RoomSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && !model.HeadwaiterId.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
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
|
||||
.Include(x => x.Dinners)
|
||||
.ThenInclude(x => x.Dinner)
|
||||
|
@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace HotelDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(HotelDataBase))]
|
||||
[Migration("20230405210621_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
[Migration("20230515204810_coursework")]
|
||||
partial class coursework
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -137,7 +137,7 @@ namespace HotelDataBaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("DinnetPrice")
|
||||
b.Property<double>("DinnerPrice")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<int>("HeadwaiterId")
|
@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace HotelDataBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
public partial class coursework : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@ -53,7 +53,7 @@ namespace HotelDataBaseImplement.Migrations
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
HeadwaiterId = table.Column<int>(type: "int", 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 =>
|
||||
{
|
@ -40,6 +40,8 @@ namespace HotelDataBaseImplement.Models
|
||||
return new ConferenceBooking()
|
||||
{
|
||||
Id = model.Id,
|
||||
ConferenceId = model.ConferenceId,
|
||||
HeadwaiterId = model.HeadwaiterId,
|
||||
Dinners = model.ConferenceBookingDinners.Select(x => new ConferenceBookingDinner
|
||||
{
|
||||
Dinner = context.Dinners.First(y => y.Id == x.Key),
|
||||
@ -49,12 +51,15 @@ namespace HotelDataBaseImplement.Models
|
||||
|
||||
public void Update(ConferenceBookingBindingModel model)
|
||||
{
|
||||
|
||||
ConferenceId = model.ConferenceId;
|
||||
HeadwaiterId = model.HeadwaiterId;
|
||||
}
|
||||
|
||||
public ConferenceBookingViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ConferenceId = ConferenceId,
|
||||
HeadwaiterId = HeadwaiterId,
|
||||
ConferenceBookingDinners = ConferenceBookingDinners
|
||||
};
|
||||
|
||||
|
@ -39,6 +39,7 @@ namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
DinnerName = model.DinnerName,
|
||||
HeadwaiterId = model.HeadwaiterId,
|
||||
DinnerPrice = model.DinnerPrice
|
||||
};
|
||||
}
|
||||
@ -48,6 +49,7 @@ namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
DinnerName = model.DinnerName,
|
||||
HeadwaiterId = model.HeadwaiterId,
|
||||
DinnerPrice = model.DinnerPrice
|
||||
};
|
||||
}
|
||||
@ -57,6 +59,7 @@ namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
return;
|
||||
}
|
||||
HeadwaiterId = model.HeadwaiterId;
|
||||
DinnerName = model.DinnerName;
|
||||
DinnerPrice = model.DinnerPrice;
|
||||
}
|
||||
@ -64,6 +67,7 @@ namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
DinnerName = DinnerName,
|
||||
HeadwaiterId = HeadwaiterId,
|
||||
DinnerPrice = DinnerPrice
|
||||
};
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ namespace HotelDataBaseImplement.Models
|
||||
RoomName = model.RoomName,
|
||||
RoomFrame = model.RoomFrame,
|
||||
RoomPrice = model.RoomPrice,
|
||||
HeadwaiterId = model.HeadwaiterId,
|
||||
MealPlanId = model.MealPlanId,
|
||||
Dinners = model.RoomDinners.Select(x => new RoomDinner
|
||||
{
|
||||
Dinner = context.Dinners.First(y => y.Id == x.Key),
|
||||
@ -62,6 +64,8 @@ namespace HotelDataBaseImplement.Models
|
||||
RoomName = model.RoomName;
|
||||
RoomFrame = model.RoomFrame;
|
||||
RoomPrice = model.RoomPrice;
|
||||
HeadwaiterId = model.HeadwaiterId;
|
||||
MealPlanId = model.MealPlanId;
|
||||
}
|
||||
|
||||
public RoomViewModel GetViewModel => new()
|
||||
@ -69,6 +73,8 @@ namespace HotelDataBaseImplement.Models
|
||||
Id = Id,
|
||||
RoomName = RoomName,
|
||||
RoomFrame = RoomFrame,
|
||||
HeadwaiterId = HeadwaiterId,
|
||||
MealPlanId = MealPlanId,
|
||||
RoomPrice = RoomPrice,
|
||||
RoomDinners = RoomDinners
|
||||
};
|
||||
|
67
Hotel/HotelRestApi/Controllers/HeadwaiterController.cs
Normal file
67
Hotel/HotelRestApi/Controllers/HeadwaiterController.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,13 +17,19 @@ namespace HotelRestApi.Controllers
|
||||
private readonly IConferenceLogic _conference;
|
||||
private readonly IMemberLogic _member;
|
||||
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;
|
||||
_conference = conference;
|
||||
_member = member;
|
||||
_mealPlan = mealPlan;
|
||||
_dinner = dinner;
|
||||
_conferenceBooking = conferenceBooking;
|
||||
_room = room;
|
||||
}
|
||||
|
||||
[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]
|
||||
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]
|
||||
public void CreateConference(ConferenceBindingModel model)
|
||||
{
|
||||
@ -223,5 +339,33 @@ namespace HotelRestApi.Controllers
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,16 @@ builder.Services.AddTransient<IMealPlanLogic, MealPlanLogic>();
|
||||
builder.Services.AddTransient<IMemberLogic, MemberLogic>();
|
||||
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.AddControllers();
|
||||
|
Loading…
Reference in New Issue
Block a user