| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using Diligent.WebAPI.Business.Interfaces;
- using Diligent.WebAPI.Data;
- using Diligent.WebAPI.Data.Entities;
- using Diligent.WebAPI.Data.HelperModels;
- using MongoDB.Driver;
-
- namespace Diligent.WebAPI.Business.Services
- {
- public class RoomRepository : BaseRepository<Room>, IRoomRepository
- {
- protected new IMongoCollection<Room> _dbCollection;
-
- public RoomRepository(IMongoDBContext context) : base(context)
- {
- _dbCollection = _mongoContext.GetCollection<Room>(typeof(Room).Name);
- }
-
- public async Task AddCustomerToRoom(Room room, string customerId)
- {
- room.Customers.Add(new CustomerDTO { CustomerId = customerId, DateOfEnteringRoom = DateTime.Now });
-
- await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
- }
-
- public async Task AddMessage(Room room, Message message)
- {
- room.Messages.Add(message);
- await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
- }
-
- public async Task<List<Room>> GetRoomsWhichSupportCreated(string supportId) =>
- await _dbCollection.Find(k => k.CreatedBy == supportId).ToListAsync();
-
- public async Task LeaveChatRoom(Room room, CustomerDTO userConnection)
- {
- room.Customers.Remove(userConnection);
-
- await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
- }
- }
- }
|