diff --git a/Hotel/Hotel.sln b/Hotel/Hotel.sln index 6332953..01ea911 100644 --- a/Hotel/Hotel.sln +++ b/Hotel/Hotel.sln @@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 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 -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 -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 Global 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}.Release|Any CPU.ActiveCfg = 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 GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hotel/HotelMongoDB/HotelMongoDB.csproj b/Hotel/HotelMongoDB/HotelMongoDB.csproj new file mode 100644 index 0000000..41750ad --- /dev/null +++ b/Hotel/HotelMongoDB/HotelMongoDB.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Hotel/HotelMongoDB/Models/MongoGuest.cs b/Hotel/HotelMongoDB/Models/MongoGuest.cs new file mode 100644 index 0000000..992916d --- /dev/null +++ b/Hotel/HotelMongoDB/Models/MongoGuest.cs @@ -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() + { + } + } +} diff --git a/Hotel/HotelMongoDB/Models/MongoHotel.cs b/Hotel/HotelMongoDB/Models/MongoHotel.cs new file mode 100644 index 0000000..695a753 --- /dev/null +++ b/Hotel/HotelMongoDB/Models/MongoHotel.cs @@ -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() + { + } + } +} diff --git a/Hotel/HotelMongoDB/Models/MongoReservation.cs b/Hotel/HotelMongoDB/Models/MongoReservation.cs new file mode 100644 index 0000000..ad5a19c --- /dev/null +++ b/Hotel/HotelMongoDB/Models/MongoReservation.cs @@ -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() + { + } + } +} diff --git a/Hotel/HotelMongoDB/Models/MongoRoom.cs b/Hotel/HotelMongoDB/Models/MongoRoom.cs new file mode 100644 index 0000000..2886add --- /dev/null +++ b/Hotel/HotelMongoDB/Models/MongoRoom.cs @@ -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() + { + } + } +} diff --git a/Hotel/HotelMongoDB/Models/MongoService.cs b/Hotel/HotelMongoDB/Models/MongoService.cs new file mode 100644 index 0000000..e8af2c8 --- /dev/null +++ b/Hotel/HotelMongoDB/Models/MongoService.cs @@ -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() + { + } + } +} diff --git a/Hotel/HotelMongoDB/Models/MongoServiceCheck.cs b/Hotel/HotelMongoDB/Models/MongoServiceCheck.cs new file mode 100644 index 0000000..df0a13a --- /dev/null +++ b/Hotel/HotelMongoDB/Models/MongoServiceCheck.cs @@ -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() + { + } + } +} diff --git a/Hotel/HotelMongoDB/Models/Sequence.cs b/Hotel/HotelMongoDB/Models/Sequence.cs new file mode 100644 index 0000000..6f08422 --- /dev/null +++ b/Hotel/HotelMongoDB/Models/Sequence.cs @@ -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; + } +} diff --git a/Hotel/HotelMongoDB/MongoDBImplement.cs b/Hotel/HotelMongoDB/MongoDBImplement.cs new file mode 100644 index 0000000..4e11337 --- /dev/null +++ b/Hotel/HotelMongoDB/MongoDBImplement.cs @@ -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 _hotelCollection; + private IMongoCollection _roomCollection; + private IMongoCollection _guestCollection; + private IMongoCollection _serviceCollection; + private IMongoCollection _reservationCollection; + private IMongoCollection _serviceCheckCollection; + private IMongoCollection _sequenceCollection; + + public MongoDBImplement() + { + var client = new MongoClient("mongodb://localhost:27017"); + _database = client.GetDatabase("hoteldb"); + + _hotelCollection = _database.GetCollection("hotel"); + _roomCollection = _database.GetCollection("room"); + _guestCollection = _database.GetCollection("guest"); + _serviceCollection = _database.GetCollection("service"); + _reservationCollection = _database.GetCollection("reservation"); + _serviceCheckCollection = _database.GetCollection("service_check"); + _sequenceCollection = _database.GetCollection("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 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 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 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 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 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 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 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); + } + } +} diff --git a/Hotel/HotelMongoDB/StorageContracts/StorageModel.cs b/Hotel/HotelMongoDB/StorageContracts/StorageModel.cs new file mode 100644 index 0000000..88adbcc --- /dev/null +++ b/Hotel/HotelMongoDB/StorageContracts/StorageModel.cs @@ -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 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 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 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 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 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 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); + } +}