Ну почти
This commit is contained in:
parent
3fde5e7e9c
commit
5a820377ca
@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.9.34728.123
|
VisualStudioVersion = 17.9.34728.123
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelAbstractions", "HotelAbstractions\HotelAbstractions.csproj", "{AD9AAD7D-EC52-40B5-A34A-8B80AD8618C8}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelAbstractions", "HotelAbstractions\HotelAbstractions.csproj", "{AD9AAD7D-EC52-40B5-A34A-8B80AD8618C8}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDatabase", "HotelDatabase\HotelDatabase.csproj", "{AB783669-67D3-48DC-9930-D4A59F923E26}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDatabase", "HotelDatabase\HotelDatabase.csproj", "{AB783669-67D3-48DC-9930-D4A59F923E26}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelView", "HotelView\HotelView.csproj", "{890038F3-3A65-4292-A852-E8536002E78E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelView", "HotelView\HotelView.csproj", "{890038F3-3A65-4292-A852-E8536002E78E}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelMongoDB", "HotelMongoDB\HotelMongoDB.csproj", "{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -27,6 +29,10 @@ Global
|
|||||||
{890038F3-3A65-4292-A852-E8536002E78E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{890038F3-3A65-4292-A852-E8536002E78E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
18
Hotel/HotelMongoDB/HotelMongoDB.csproj
Normal file
18
Hotel/HotelMongoDB/HotelMongoDB.csproj
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MongoDB.Bson" Version="2.25.0" />
|
||||||
|
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\HotelAbstractions\HotelAbstractions.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
35
Hotel/HotelMongoDB/Models/MongoGuest.cs
Normal file
35
Hotel/HotelMongoDB/Models/MongoGuest.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using HotelAbstractions.Models;
|
||||||
|
|
||||||
|
namespace HotelMongoDB.Models
|
||||||
|
{
|
||||||
|
public class MongoGuest
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string FIO { get; set; } = string.Empty;
|
||||||
|
public string PhoneNumber { get; set; } = string.Empty;
|
||||||
|
public string BirthDate { get; set; } = string.Empty;
|
||||||
|
public string PassportId { get; set; } = string.Empty;
|
||||||
|
public string Gender { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public MongoGuest(HotelAbstractions.Models.Guest model)
|
||||||
|
{
|
||||||
|
FIO = model.FIO;
|
||||||
|
PhoneNumber = model.PhoneNumber;
|
||||||
|
BirthDate = model.BirthDate.ToString("d");
|
||||||
|
PassportId = model.PassportId;
|
||||||
|
Gender = model.Gender.ToString();
|
||||||
|
}
|
||||||
|
public MongoGuest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
Hotel/HotelMongoDB/Models/MongoHotel.cs
Normal file
33
Hotel/HotelMongoDB/Models/MongoHotel.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
|
||||||
|
|
||||||
|
namespace HotelMongoDB.Models
|
||||||
|
{
|
||||||
|
public class MongoHotel
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string HotelName { get; set; } = string.Empty;
|
||||||
|
public string Address { get; set; } = string.Empty;
|
||||||
|
public string CountStar { get; set; } = string.Empty;
|
||||||
|
public string CountRoom { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public MongoHotel(HotelAbstractions.Models.Hotel model)
|
||||||
|
{
|
||||||
|
HotelName = model.HotelName;
|
||||||
|
Address = model.Address;
|
||||||
|
CountStar = model.CountStar.ToString();
|
||||||
|
CountRoom = model.CountRoom.ToString();
|
||||||
|
}
|
||||||
|
public MongoHotel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
Hotel/HotelMongoDB/Models/MongoReservation.cs
Normal file
33
Hotel/HotelMongoDB/Models/MongoReservation.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HotelMongoDB.Models
|
||||||
|
{
|
||||||
|
public class MongoReservation
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string GuestId { get; set; } = string.Empty;
|
||||||
|
public string RoomId { get; set; } = string.Empty;
|
||||||
|
public string ArrivalDate { get; set; } = string.Empty;
|
||||||
|
public string DepartureDate { get; set; } = string.Empty;
|
||||||
|
public string Price { get; set; } = string.Empty;
|
||||||
|
public MongoReservation(HotelAbstractions.Models.Reservation model, string guest_id, string room_id)
|
||||||
|
{
|
||||||
|
GuestId = guest_id;
|
||||||
|
RoomId = room_id;
|
||||||
|
ArrivalDate = model.ArrivalDate.ToString("d");
|
||||||
|
DepartureDate = model.DepartureDate.ToString("d");
|
||||||
|
Price = model.Price.ToString();
|
||||||
|
}
|
||||||
|
public MongoReservation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
Hotel/HotelMongoDB/Models/MongoRoom.cs
Normal file
41
Hotel/HotelMongoDB/Models/MongoRoom.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HotelMongoDB.Models
|
||||||
|
{
|
||||||
|
public class MongoRoom
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string HotelId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Category { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string CountPlace { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Flor { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Number { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Price { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public MongoRoom(HotelAbstractions.Models.Room model, string hotel_id)
|
||||||
|
{
|
||||||
|
HotelId = hotel_id;
|
||||||
|
Category = model.Category;
|
||||||
|
CountPlace = model.CountPlace.ToString();
|
||||||
|
Flor = model.Flor.ToString();
|
||||||
|
Number = model.Number;
|
||||||
|
Price = model.Price.ToString();
|
||||||
|
}
|
||||||
|
public MongoRoom()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
Hotel/HotelMongoDB/Models/MongoService.cs
Normal file
29
Hotel/HotelMongoDB/Models/MongoService.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HotelMongoDB.Models
|
||||||
|
{
|
||||||
|
public class MongoService
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string Price { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
|
||||||
|
public MongoService(HotelAbstractions.Models.Service model)
|
||||||
|
{
|
||||||
|
Name = model.Name;
|
||||||
|
Price = model.Price.ToString();
|
||||||
|
}
|
||||||
|
public MongoService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
Hotel/HotelMongoDB/Models/MongoServiceCheck.cs
Normal file
31
Hotel/HotelMongoDB/Models/MongoServiceCheck.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HotelMongoDB.Models
|
||||||
|
{
|
||||||
|
public class MongoServiceCheck
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string ReservationId { get; set; } = string.Empty;
|
||||||
|
public string ServiceId { get; set; } = string.Empty;
|
||||||
|
public string Count { get; set; } = string.Empty;
|
||||||
|
public string DateTime { get; set; } = string.Empty;
|
||||||
|
public MongoServiceCheck(HotelAbstractions.Models.ServiceCheck model, string reservation_id, string service_id)
|
||||||
|
{
|
||||||
|
ReservationId = reservation_id;
|
||||||
|
ServiceId = service_id;
|
||||||
|
Count = model.Count.ToString();
|
||||||
|
DateTime = model.DateTime.ToString();
|
||||||
|
}
|
||||||
|
public MongoServiceCheck()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
Hotel/HotelMongoDB/Models/Sequence.cs
Normal file
20
Hotel/HotelMongoDB/Models/Sequence.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HotelMongoDB.Models
|
||||||
|
{
|
||||||
|
public class Sequence
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; } = string.Empty;
|
||||||
|
public string Sql_id { get; set; } = string.Empty;
|
||||||
|
public string Mongo_id { get; set; } = string.Empty;
|
||||||
|
public string Table_name { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
240
Hotel/HotelMongoDB/MongoDBImplement.cs
Normal file
240
Hotel/HotelMongoDB/MongoDBImplement.cs
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
using HotelMongoDB.StorageContracts;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using HotelMongoDB.Models;
|
||||||
|
using HotelAbstractions.Models;
|
||||||
|
|
||||||
|
namespace HotelMongoDB
|
||||||
|
{
|
||||||
|
public class MongoDBImplement : StorageModel
|
||||||
|
{
|
||||||
|
private IMongoDatabase _database;
|
||||||
|
private IMongoCollection<MongoHotel> _hotelCollection;
|
||||||
|
private IMongoCollection<MongoRoom> _roomCollection;
|
||||||
|
private IMongoCollection<MongoGuest> _guestCollection;
|
||||||
|
private IMongoCollection<MongoService> _serviceCollection;
|
||||||
|
private IMongoCollection<MongoReservation> _reservationCollection;
|
||||||
|
private IMongoCollection<MongoServiceCheck> _serviceCheckCollection;
|
||||||
|
private IMongoCollection<Sequence> _sequenceCollection;
|
||||||
|
|
||||||
|
public MongoDBImplement()
|
||||||
|
{
|
||||||
|
var client = new MongoClient("mongodb://localhost:27017");
|
||||||
|
_database = client.GetDatabase("hoteldb");
|
||||||
|
|
||||||
|
_hotelCollection = _database.GetCollection<MongoHotel>("hotel");
|
||||||
|
_roomCollection = _database.GetCollection<MongoRoom>("room");
|
||||||
|
_guestCollection = _database.GetCollection<MongoGuest>("guest");
|
||||||
|
_serviceCollection = _database.GetCollection<MongoService>("service");
|
||||||
|
_reservationCollection = _database.GetCollection<MongoReservation>("reservation");
|
||||||
|
_serviceCheckCollection = _database.GetCollection<MongoServiceCheck>("service_check");
|
||||||
|
_sequenceCollection = _database.GetCollection<Sequence>("sequence");
|
||||||
|
}
|
||||||
|
|
||||||
|
// hotel
|
||||||
|
public override void AddHotel(Hotel hotel)
|
||||||
|
{
|
||||||
|
var art = new MongoHotel(hotel);
|
||||||
|
_hotelCollection.InsertOne(art);
|
||||||
|
|
||||||
|
var seq = new Sequence { Sql_id = hotel.Id.ToString(), Mongo_id = art.Id, Table_name = "hotel" };
|
||||||
|
_sequenceCollection.InsertOne(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<MongoHotel> GetHotels()
|
||||||
|
{
|
||||||
|
return _hotelCollection.Find(_ => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MongoHotel GetHotelById(string id)
|
||||||
|
{
|
||||||
|
return _hotelCollection.Find(hotel => hotel.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateHotel(MongoHotel hotel)
|
||||||
|
{
|
||||||
|
_hotelCollection.ReplaceOne(c => c.Id == hotel.Id, hotel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeleteHotel(string id)
|
||||||
|
{
|
||||||
|
_hotelCollection.DeleteOne(hotel => hotel.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Room
|
||||||
|
public override void AddRoom(Room room)
|
||||||
|
{
|
||||||
|
string hotel_id = GetMongoId("hotel", room.HotelId.ToString());
|
||||||
|
|
||||||
|
var art = new MongoRoom(room, hotel_id);
|
||||||
|
_roomCollection.InsertOne(art);
|
||||||
|
|
||||||
|
var seq = new Sequence { Sql_id = room.Id.ToString(), Mongo_id = art.Id, Table_name = "room" };
|
||||||
|
_sequenceCollection.InsertOne(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<MongoRoom> GetRooms()
|
||||||
|
{
|
||||||
|
return _roomCollection.Find(_ => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MongoRoom GetRoomById(string id)
|
||||||
|
{
|
||||||
|
return _roomCollection.Find(room => room.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateRoom(MongoRoom room)
|
||||||
|
{
|
||||||
|
_roomCollection.ReplaceOne(c => c.Id == room.Id, room);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeleteRoom(string id)
|
||||||
|
{
|
||||||
|
_roomCollection.DeleteOne(room => room.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guest
|
||||||
|
public override void AddGuest(Guest guest)
|
||||||
|
{
|
||||||
|
var cat = new MongoGuest(guest);
|
||||||
|
_guestCollection.InsertOne(cat);
|
||||||
|
|
||||||
|
var seq = new Sequence { Sql_id = guest.Id.ToString(), Mongo_id = cat.Id, Table_name = "guest" };
|
||||||
|
_sequenceCollection.InsertOne(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<MongoGuest> GetGuests()
|
||||||
|
{
|
||||||
|
return _guestCollection.Find(_ => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MongoGuest GetGuestById(string id)
|
||||||
|
{
|
||||||
|
return _guestCollection.Find(guest => guest.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateGuest(MongoGuest guest)
|
||||||
|
{
|
||||||
|
_guestCollection.ReplaceOne(r => r.Id == guest.Id, guest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeleteGuest(string id)
|
||||||
|
{
|
||||||
|
_guestCollection.DeleteOne(guest => guest.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service
|
||||||
|
public override void AddService(Service service)
|
||||||
|
{
|
||||||
|
var cat = new MongoService(service);
|
||||||
|
_serviceCollection.InsertOne(cat);
|
||||||
|
|
||||||
|
var seq = new Sequence { Sql_id = service.Id.ToString(), Mongo_id = cat.Id, Table_name = "service" };
|
||||||
|
_sequenceCollection.InsertOne(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<MongoService> GetServices()
|
||||||
|
{
|
||||||
|
return _serviceCollection.Find(_ => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MongoService GetServiceById(string id)
|
||||||
|
{
|
||||||
|
return _serviceCollection.Find(model => model.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateService(MongoService service)
|
||||||
|
{
|
||||||
|
_serviceCollection.ReplaceOne(m => m.Id == service.Id, service);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeleteService(string id)
|
||||||
|
{
|
||||||
|
_serviceCollection.DeleteOne(model => model.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reservation
|
||||||
|
public override void AddReservation(Reservation reservation)
|
||||||
|
{
|
||||||
|
string room_id = GetMongoId("room", reservation.RoomId.ToString());
|
||||||
|
string guest_id = GetMongoId("guest", reservation.GuestId.ToString());
|
||||||
|
|
||||||
|
var art = new MongoReservation(reservation, guest_id, room_id);
|
||||||
|
_reservationCollection.InsertOne(art);
|
||||||
|
|
||||||
|
var seq = new Sequence { Sql_id = reservation.Id.ToString(), Mongo_id = art.Id, Table_name = "reservation" };
|
||||||
|
_sequenceCollection.InsertOne(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<MongoReservation> GetReservations()
|
||||||
|
{
|
||||||
|
return _reservationCollection.Find(_ => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MongoReservation GetReservationById(string id)
|
||||||
|
{
|
||||||
|
return _reservationCollection.Find(Reservation => Reservation.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateReservation(MongoReservation Reservation)
|
||||||
|
{
|
||||||
|
_reservationCollection.ReplaceOne(b => b.Id == Reservation.Id, Reservation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeleteReservation(string id)
|
||||||
|
{
|
||||||
|
_reservationCollection.DeleteOne(Reservation => Reservation.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ServiceCheck
|
||||||
|
public override void AddServiceCheck(ServiceCheck serviceCheck)
|
||||||
|
{
|
||||||
|
string reservation_id = GetMongoId("reservation", serviceCheck.ReservationId.ToString());
|
||||||
|
string service_id = GetMongoId("service", serviceCheck.ServiceId.ToString());
|
||||||
|
|
||||||
|
var art = new MongoServiceCheck(serviceCheck, reservation_id, service_id);
|
||||||
|
_serviceCheckCollection.InsertOne(art);
|
||||||
|
|
||||||
|
var seq = new Sequence { Sql_id = serviceCheck.Id.ToString(), Mongo_id = art.Id, Table_name = "service_check" };
|
||||||
|
_sequenceCollection.InsertOne(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<MongoServiceCheck> GetServiceChecks()
|
||||||
|
{
|
||||||
|
return _serviceCheckCollection.Find(_ => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MongoServiceCheck GetServiceCheckById(string id)
|
||||||
|
{
|
||||||
|
return _serviceCheckCollection.Find(ServiceCheck => ServiceCheck.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateServiceCheck(MongoServiceCheck ServiceCheck)
|
||||||
|
{
|
||||||
|
_serviceCheckCollection.ReplaceOne(b => b.Id == ServiceCheck.Id, ServiceCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DeleteServiceCheck(string id)
|
||||||
|
{
|
||||||
|
_serviceCheckCollection.DeleteOne(ServiceCheck => ServiceCheck.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Sequence> GetSequence()
|
||||||
|
{
|
||||||
|
return _sequenceCollection.Find(_ => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetMongoId(string tableName, string sqlId)
|
||||||
|
{
|
||||||
|
var sequence = _sequenceCollection.Find(s => s.Table_name == tableName && s.Sql_id == sqlId).FirstOrDefault();
|
||||||
|
|
||||||
|
return sequence?.Mongo_id ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteSequence(string id)
|
||||||
|
{
|
||||||
|
_sequenceCollection.DeleteOne(Sequence => Sequence.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Hotel/HotelMongoDB/StorageContracts/StorageModel.cs
Normal file
60
Hotel/HotelMongoDB/StorageContracts/StorageModel.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using HotelAbstractions.Models;
|
||||||
|
using HotelMongoDB.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HotelMongoDB.StorageContracts
|
||||||
|
{
|
||||||
|
public abstract class StorageModel
|
||||||
|
{
|
||||||
|
|
||||||
|
// Hotel
|
||||||
|
public abstract void AddHotel(Hotel hotel);
|
||||||
|
public abstract List<MongoHotel> GetHotels();
|
||||||
|
public abstract MongoHotel GetHotelById(string id);
|
||||||
|
public abstract void UpdateHotel(MongoHotel hotel);
|
||||||
|
public abstract void DeleteHotel(string id);
|
||||||
|
|
||||||
|
// Room
|
||||||
|
public abstract void AddRoom(Room room);
|
||||||
|
public abstract List<MongoRoom> GetRooms();
|
||||||
|
public abstract MongoRoom GetRoomById(string id);
|
||||||
|
public abstract void UpdateRoom(MongoRoom room);
|
||||||
|
public abstract void DeleteRoom(string id);
|
||||||
|
|
||||||
|
// Guest
|
||||||
|
public abstract void AddGuest(Guest guest);
|
||||||
|
public abstract List<MongoGuest> GetGuests();
|
||||||
|
public abstract MongoGuest GetGuestById(string id);
|
||||||
|
public abstract void UpdateGuest(MongoGuest guest);
|
||||||
|
public abstract void DeleteGuest(string id);
|
||||||
|
|
||||||
|
// Service
|
||||||
|
public abstract void AddService(Service service);
|
||||||
|
public abstract List<MongoService> GetServices();
|
||||||
|
public abstract MongoService GetServiceById(string id);
|
||||||
|
public abstract void UpdateService(MongoService service);
|
||||||
|
public abstract void DeleteService(string id);
|
||||||
|
|
||||||
|
// Reservation
|
||||||
|
public abstract void AddReservation(Reservation reservation);
|
||||||
|
public abstract List<MongoReservation> GetReservations();
|
||||||
|
public abstract MongoReservation GetReservationById(string id);
|
||||||
|
public abstract void UpdateReservation(MongoReservation reservation);
|
||||||
|
public abstract void DeleteReservation(string id);
|
||||||
|
|
||||||
|
|
||||||
|
// ServiceCheck
|
||||||
|
public abstract void AddServiceCheck(ServiceCheck serviceCheck);
|
||||||
|
public abstract List<MongoServiceCheck> GetServiceChecks();
|
||||||
|
public abstract MongoServiceCheck GetServiceCheckById(string id);
|
||||||
|
public abstract void UpdateServiceCheck(MongoServiceCheck serviceCheck);
|
||||||
|
public abstract void DeleteServiceCheck(string id);
|
||||||
|
|
||||||
|
|
||||||
|
public abstract string GetMongoId(string tableName, string sqlId);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user