using Diligent.WebAPI.Business.Interfaces; using Diligent.WebAPI.Data; using Diligent.WebAPI.Data.Entities; using Diligent.WebAPI.Data.HelperModels; using MongoDB.Driver; using System.Diagnostics.CodeAnalysis; namespace Diligent.WebAPI.Business.Services { [ExcludeFromCodeCoverage] public class RoomRepository : BaseRepository, IRoomRepository { protected new IMongoCollection _dbCollection; public RoomRepository(IMongoDBContext context) : base(context) { _dbCollection = _mongoContext.GetCollection(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> 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); } } }