School Commit Init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
CREATE DATABASE Hotel;
|
||||
USE Hotel;
|
||||
|
||||
CREATE TABLE Guest(
|
||||
Id INT PRIMARY KEY IDENTITY(1,1),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
phone VARCHAR(255) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE Room(
|
||||
Id INT PRIMARY KEY IDENTITY(1,1),
|
||||
type VARCHAR(255) NOT NULL,
|
||||
capacity int NOT NULL,
|
||||
price INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE Reservation(
|
||||
Id INT PRIMARY KEY IDENTITY(1,1),
|
||||
guestId INT NOT NULL,
|
||||
roomId INT NOT NULL,
|
||||
checkIn DATE NOT NULL,
|
||||
checkOut DATE NOT NULL,
|
||||
paid BOOLEAN NOT NULL,
|
||||
FOREIGN KEY (guestId) REFERENCES Guest(Id),
|
||||
FOREIGN KEY (roomId) REFERENCES Room(Id)
|
||||
);
|
||||
|
||||
CREATE TABLE Payment(
|
||||
Id INT PRIMARY KEY IDENTITY(1,1),
|
||||
reservationId INT NOT NULL,
|
||||
amount INT NOT NULL,
|
||||
serviceId INT NOT NULL,
|
||||
FOREIGN KEY (reservationId) REFERENCES Reservation(Id),
|
||||
FOREIGN KEY (serviceId) REFERENCES Service(Id)
|
||||
);
|
||||
|
||||
CREATE TABLE Service(
|
||||
Id INT PRIMARY KEY IDENTITY(1,1),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description VARCHAR(255) NOT NULL,
|
||||
price INT NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exam", "Exam\Exam.csproj", "{7AD9D21B-9ECC-444F-8AE3-9A96E2FA2134}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7AD9D21B-9ECC-444F-8AE3-9A96E2FA2134}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7AD9D21B-9ECC-444F-8AE3-9A96E2FA2134}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7AD9D21B-9ECC-444F-8AE3-9A96E2FA2134}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7AD9D21B-9ECC-444F-8AE3-9A96E2FA2134}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5DA96924-77EB-4666-8775-6A87E8A88D7B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,44 @@
|
||||
using Exam.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Exam.Context
|
||||
{
|
||||
public class DataContext : DbContext
|
||||
{
|
||||
public DataContext(DbContextOptions<DataContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<Flight> Flights { get; set; }
|
||||
public DbSet<Hotel> Hotels { get; set; }
|
||||
public DbSet<Reservation> Reservations { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Flight>(f =>
|
||||
{
|
||||
f.Property<int>("FlightId").HasColumnName("flightId");
|
||||
f.Property<DateTime>("Date").HasColumnName("date");
|
||||
f.Property<string>("DestinationCity").HasColumnName("destinationCity");
|
||||
f.Property<int>("AvailableSeats").HasColumnName("availableSeats");
|
||||
});
|
||||
modelBuilder.Entity<Hotel>(f =>
|
||||
{
|
||||
f.Property<int>("HotelId").HasColumnName("hotelId");
|
||||
f.Property<DateTime>("Date").HasColumnName("date");
|
||||
f.Property<string>("HotelName").HasColumnName("hotelname");
|
||||
f.Property<string>("City").HasColumnName("city");
|
||||
f.Property<int>("AvailableRooms").HasColumnName("availableRooms");
|
||||
});
|
||||
modelBuilder.Entity<Reservation>(f =>
|
||||
{
|
||||
f.Property<int>("Id").HasColumnName("id");
|
||||
f.Property<DateTime>("Date").HasColumnName("date");
|
||||
f.Property<string>("Person").HasColumnName("person");
|
||||
f.Property<string>("Type").HasColumnName("type");
|
||||
f.Property<int>("IdReservedResource").HasColumnName("idReservedResource");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using Exam.Extensions;
|
||||
using Exam.Models;
|
||||
using Exam.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Exam.Controllers
|
||||
{
|
||||
[Route("/")]
|
||||
public class BaseController : Controller
|
||||
{
|
||||
private readonly IService _service;
|
||||
public BaseController(IService service) => _service = service;
|
||||
|
||||
[HttpGet]
|
||||
[Route("search")]
|
||||
public IActionResult Login()
|
||||
{
|
||||
return View("~/Views/Search.cshtml");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("search")]
|
||||
public IActionResult Login(UserSearch userSearch)
|
||||
{
|
||||
HttpContext.Session.Set<UserSearch>("usersearch", userSearch);
|
||||
return Redirect("/");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("/")]
|
||||
public IActionResult Home()
|
||||
{
|
||||
if (HttpContext.Session.GetString("usersearch") == null)
|
||||
{
|
||||
return View("~/Views/Search.cshtml");
|
||||
}
|
||||
return View("~/Views/Home.cshtml");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("flights")]
|
||||
public IActionResult Flights()
|
||||
{
|
||||
var userSearch = HttpContext.Session.Get<UserSearch>("usersearch");
|
||||
if (userSearch == null)
|
||||
{
|
||||
return Redirect("/");
|
||||
}
|
||||
return View("~/Views/Flights.cshtml", _service.ShowFlightsByDateAndCity(userSearch.Date, userSearch.City));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("hotels")]
|
||||
public IActionResult Hotels()
|
||||
{
|
||||
var userSearch = HttpContext.Session.Get<UserSearch>("usersearch");
|
||||
if (userSearch == null)
|
||||
{
|
||||
return Redirect("/");
|
||||
}
|
||||
return View("~/Views/Hotels.cshtml", _service.ShowHotelsByDateAndCity(userSearch.Date, userSearch.City));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("reserve-flight/{id}")]
|
||||
public IActionResult ReserveFlight(int id)
|
||||
{
|
||||
var userSearch = HttpContext.Session.Get<UserSearch>("usersearch");
|
||||
if (userSearch == null)
|
||||
{
|
||||
return Redirect("/");
|
||||
}
|
||||
var reservation = new Reservation
|
||||
{
|
||||
Person = userSearch.Name,
|
||||
Date = userSearch.Date,
|
||||
Type = "Flight",
|
||||
IdReservedResource = id
|
||||
};
|
||||
|
||||
var result = _service.AddReservavtion(reservation);
|
||||
if(result != -1)
|
||||
{
|
||||
_service.DecrementFlightSeats(id);
|
||||
return Ok(result);
|
||||
}
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("reserve-hotel/{id}")]
|
||||
public IActionResult ReserveHotel(int id)
|
||||
{
|
||||
var userSearch = HttpContext.Session.Get<UserSearch>("usersearch");
|
||||
if (userSearch == null)
|
||||
{
|
||||
return Redirect("/");
|
||||
}
|
||||
var reservation = new Reservation
|
||||
{
|
||||
Person = userSearch.Name,
|
||||
Date = userSearch.Date,
|
||||
Type = "Hotel",
|
||||
IdReservedResource = id
|
||||
};
|
||||
|
||||
var result = _service.AddReservavtion(reservation);
|
||||
if (result != -1)
|
||||
{
|
||||
_service.DecrementHotelRooms(id);
|
||||
return Ok(result);
|
||||
}
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Exam.Enums
|
||||
{
|
||||
public enum ReservationType
|
||||
{
|
||||
Flight,
|
||||
Hotel
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>https</ActiveDebugProfile>
|
||||
<View_SelectedScaffolderID>RazorViewEmptyScaffolder</View_SelectedScaffolderID>
|
||||
<View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Exam.Extensions
|
||||
{
|
||||
public static class SessionExtension
|
||||
{
|
||||
public static void Set<T>(this ISession session, string key, T value)
|
||||
{
|
||||
session.SetString(key, JsonSerializer.Serialize(value));
|
||||
}
|
||||
|
||||
public static T? Get<T>(this ISession session, string key)
|
||||
{
|
||||
var value = session.GetString(key);
|
||||
return value == null ? default : JsonSerializer.Deserialize<T>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Exam.Models
|
||||
{
|
||||
public class Flight
|
||||
{
|
||||
public int FlightId { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public required string DestinationCity { get; set; }
|
||||
public int AvailableSeats { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Exam.Models
|
||||
{
|
||||
public class Hotel
|
||||
{
|
||||
public int HotelId { get; set; }
|
||||
public required string HotelName { get; set;}
|
||||
public DateTime Date { get; set; }
|
||||
public required string City { get; set; }
|
||||
public int AvailableRooms { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Exam.Enums;
|
||||
|
||||
namespace Exam.Models
|
||||
{
|
||||
public class Reservation
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public required string Person { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public required string Type { get; set; }
|
||||
public int IdReservedResource { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Exam.Models
|
||||
{
|
||||
public class UserSearch
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public required string City { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using Exam.Context;
|
||||
using Exam.Repositories;
|
||||
using Exam.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Exam
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
builder.Services.AddSession(options =>
|
||||
{
|
||||
options.Cookie.Name = "SessionId";
|
||||
options.Cookie.IsEssential = true;
|
||||
});
|
||||
builder.Services.AddDbContext<DataContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("DbConnection")));
|
||||
|
||||
builder.Services.AddScoped<IRepository, Repository>();
|
||||
builder.Services.AddScoped<IService,Service>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
app.UseSession();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:27888",
|
||||
"sslPort": 44301
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5082",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7084;http://localhost:5082",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Exam.Models;
|
||||
|
||||
namespace Exam.Repositories
|
||||
{
|
||||
public interface IRepository
|
||||
{
|
||||
public List<Flight> ShowFlightsByDateAndCity(DateTime date, string city);
|
||||
public List<Hotel> ShowHotelsByDateAndCity(DateTime date, string city);
|
||||
public int AddReservavtion(Reservation reservation);
|
||||
public bool RemoveReservavtions(List<int> ids);
|
||||
public void DecrementFlightSeats(int id);
|
||||
public void DecrementHotelRooms(int id);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Exam.Context;
|
||||
using Exam.Models;
|
||||
|
||||
namespace Exam.Repositories
|
||||
{
|
||||
public class Repository : IRepository
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
public Repository(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public int AddReservavtion(Reservation reservation)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Add(reservation);
|
||||
_context.SaveChanges();
|
||||
return reservation.Id;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool RemoveReservavtions(List<int> ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entities = _context.Reservations.Where(r => ids.Contains(r.Id)).ToList();
|
||||
_context.RemoveRange(entities);
|
||||
_context.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Flight> ShowFlightsByDateAndCity(DateTime date, string city)
|
||||
{
|
||||
return _context.Flights.Where(f => f.Date.Equals(date) && f.DestinationCity.Equals(city) && f.AvailableSeats > 0).ToList();
|
||||
}
|
||||
|
||||
public List<Hotel> ShowHotelsByDateAndCity(DateTime date, string city)
|
||||
{
|
||||
return _context.Hotels.Where(h => h.Date.Equals(date) && h.City.Equals(city) && h.AvailableRooms > 0).ToList();
|
||||
}
|
||||
|
||||
public void DecrementFlightSeats(int id)
|
||||
{
|
||||
_context.Flights.Where(f => f.FlightId == id).FirstOrDefault().AvailableSeats--;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void DecrementHotelRooms(int id)
|
||||
{
|
||||
_context.Hotels.Where(f => f.HotelId == id).FirstOrDefault().AvailableRooms--;
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Exam.Models;
|
||||
|
||||
namespace Exam.Services
|
||||
{
|
||||
public interface IService
|
||||
{
|
||||
public List<Flight> ShowFlightsByDateAndCity(DateTime date, string city);
|
||||
public List<Hotel> ShowHotelsByDateAndCity(DateTime date, string city);
|
||||
public int AddReservavtion(Reservation flight);
|
||||
public bool RemoveReservavtions(List<int> ids);
|
||||
|
||||
public void DecrementFlightSeats(int id);
|
||||
public void DecrementHotelRooms(int id);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Exam.Models;
|
||||
using Exam.Repositories;
|
||||
|
||||
namespace Exam.Services
|
||||
{
|
||||
public class Service : IService
|
||||
{
|
||||
private readonly IRepository _repository;
|
||||
|
||||
public Service(IRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public int AddReservavtion(Reservation flight)
|
||||
{
|
||||
return _repository.AddReservavtion(flight);
|
||||
}
|
||||
|
||||
public bool RemoveReservavtions(List<int> ids)
|
||||
{
|
||||
return _repository.RemoveReservavtions(ids);
|
||||
}
|
||||
|
||||
public List<Flight> ShowFlightsByDateAndCity(DateTime date, string city)
|
||||
{
|
||||
return _repository.ShowFlightsByDateAndCity(date, city);
|
||||
}
|
||||
|
||||
public List<Hotel> ShowHotelsByDateAndCity(DateTime date, string city)
|
||||
{
|
||||
return _repository.ShowHotelsByDateAndCity(date, city);
|
||||
}
|
||||
|
||||
public void DecrementFlightSeats(int id)
|
||||
{
|
||||
_repository.DecrementFlightSeats(id);
|
||||
}
|
||||
public void DecrementHotelRooms(int id)
|
||||
{
|
||||
_repository.DecrementHotelRooms(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
@model List<Exam.Models.Flight>
|
||||
|
||||
|
||||
<div class="container text-center">
|
||||
<h3>Welcome</h3>
|
||||
<table class="container"
|
||||
id="newsTable"
|
||||
style="
|
||||
margin: 30px;
|
||||
border: 1px solid;
|
||||
border-color: black;
|
||||
border-collapse: collapse;
|
||||
">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Flight Id</th>
|
||||
<th>Date</th>
|
||||
<th>Destination City</th>
|
||||
<th>Available Seats</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr id="row-@item.FlightId">
|
||||
<td>@item.FlightId </td>
|
||||
<td>@item.Date.ToString("dd-MM-yyyy") </td>
|
||||
<td>@item.DestinationCity </td>
|
||||
<td id="availableSeats-@item.FlightId">@item.AvailableSeats</td>
|
||||
<td>
|
||||
<button onclick="ReserveFlight(@item.FlightId)">
|
||||
Reserve
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<a type="button"
|
||||
class="btn btn-dark"
|
||||
name="hotelButton"
|
||||
href="/hotels"
|
||||
style="margin: 30px">
|
||||
Hotels
|
||||
</a>
|
||||
<a type="button"
|
||||
class="btn btn-dark"
|
||||
name="hotelButton"
|
||||
href="/cancelAll"
|
||||
style="margin: 30px">
|
||||
Cancel All Reservations
|
||||
</a>
|
||||
</table>
|
||||
<script>
|
||||
function ReserveFlight(id) {
|
||||
$.ajax({
|
||||
url: `/reserve-flight/${id}`,
|
||||
success: () => {
|
||||
var availableSeats = parseInt($(`#availableSeats-${id}`).html())
|
||||
if (availableSeats > 1) {
|
||||
$(`#availableSeats-${id}`).html(availableSeats - 1)
|
||||
}
|
||||
else {
|
||||
$(`#row-${id}`).remove();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
<div class="container text-center" id="index-page">
|
||||
<h2>Flights or Hotels</h2>
|
||||
<a type="button"
|
||||
class="btn btn-primary btn-block"
|
||||
href="/flights">
|
||||
Flights
|
||||
</a>
|
||||
<a type="button"
|
||||
class="btn btn-primary btn-block"
|
||||
href="/hotels">
|
||||
Hotels
|
||||
</a>
|
||||
</div>
|
||||
@@ -0,0 +1,72 @@
|
||||
@model List<Exam.Models.Hotel>
|
||||
|
||||
|
||||
<div class="container text-center">
|
||||
<h3>Welcome</h3>
|
||||
<table class="container"
|
||||
id="newsTable"
|
||||
style="
|
||||
margin: 30px;
|
||||
border: 1px solid;
|
||||
border-color: black;
|
||||
border-collapse: collapse;
|
||||
">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Hotel Id</th>
|
||||
<th>Hotel Name</th>
|
||||
<th>Date</th>
|
||||
<th>City</th>
|
||||
<th>Available Rooms</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr id="row-@item.HotelId">
|
||||
<td>@item.HotelId </td>
|
||||
<td>@item.HotelName</td>
|
||||
<td>@item.Date.ToString("dd-MM-yyyy") </td>
|
||||
<td>@item.City </td>
|
||||
<td id="availableRooms-@item.HotelId">@item.AvailableRooms</td>
|
||||
<td>
|
||||
<button onclick="ReserveHotel(@item.HotelId)">
|
||||
Reserve
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<a type="button"
|
||||
class="btn btn-dark"
|
||||
name="hotelButton"
|
||||
href="/flights"
|
||||
style="margin: 30px">
|
||||
Flights
|
||||
</a>
|
||||
<a type="button"
|
||||
class="btn btn-dark"
|
||||
name="hotelButton"
|
||||
href="/cancelAll"
|
||||
style="margin: 30px">
|
||||
Cancel All Reservations
|
||||
</a>
|
||||
</table>
|
||||
<script>
|
||||
function ReserveHotel(id) {
|
||||
$.ajax({
|
||||
url: `/reserve-hotel/${id}`,
|
||||
success: () => {
|
||||
var availableRooms = parseInt($(`#availableRooms-${id}`).html())
|
||||
if (availableRooms > 1) {
|
||||
$(`#availableRooms-${id}`).html(availableRooms - 1)
|
||||
}
|
||||
else {
|
||||
$(`#row-${id}`).remove();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
@@ -0,0 +1,35 @@
|
||||
<form method="post" action="/search" class="container">
|
||||
<h2>Login</h2>
|
||||
<div class="mb-3 mt-3">
|
||||
<label for="name" class="form-label">Name:</label>
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
id="name"
|
||||
placeholder="Enter name"
|
||||
required
|
||||
name="name" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="city" class="form-label">City:</label>
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
id="city"
|
||||
placeholder="Enter city"
|
||||
required
|
||||
name="city" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="date" class="form-label">Date:</label>
|
||||
<input type="date" id="date" class="form-control" required name="date" />
|
||||
</div>
|
||||
<button class="btn btn-primary" name="loginButton" type="submit">
|
||||
Begin Reservation
|
||||
</button>
|
||||
</form>
|
||||
@if (ViewBag.Error != null)
|
||||
{
|
||||
<div class="alert alert-danger alert-dismissible fade show m-3">
|
||||
<strong>Error!</strong> @ViewBag.Error
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - Exam</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/Exam.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Exam</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2024 - Exam
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,48 @@
|
||||
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0077cc;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
|
||||
@@ -0,0 +1,3 @@
|
||||
@using Exam
|
||||
@using Exam.Models
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DbConnection": "Data Source=danielcujba\\sqlexpress;Initial Catalog=ExamDb;Integrated Security=True;Trust Server Certificate=True"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
html {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
|
||||
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
|
||||
}
|
||||
|
||||
html {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin-bottom: 60px;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
@@ -0,0 +1,4 @@
|
||||
// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
// for details on configuring this project to bundle and minify static web assets.
|
||||
|
||||
// Write your JavaScript code.
|
||||
Reference in New Issue
Block a user