Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RoomRepository.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Diligent.WebAPI.Business.Interfaces;
  2. using Diligent.WebAPI.Data;
  3. using Diligent.WebAPI.Data.Entities;
  4. using Diligent.WebAPI.Data.HelperModels;
  5. using MongoDB.Driver;
  6. using System.Diagnostics.CodeAnalysis;
  7. namespace Diligent.WebAPI.Business.Services
  8. {
  9. [ExcludeFromCodeCoverage]
  10. public class RoomRepository : BaseRepository<Room>, IRoomRepository
  11. {
  12. protected new IMongoCollection<Room> _dbCollection;
  13. public RoomRepository(IMongoDBContext context) : base(context)
  14. {
  15. _dbCollection = _mongoContext.GetCollection<Room>(typeof(Room).Name);
  16. }
  17. public async Task AddCustomerToRoom(Room room, string customerId)
  18. {
  19. room.Customers.Add(new CustomerDTO { CustomerId = customerId, DateOfEnteringRoom = DateTime.Now });
  20. await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
  21. }
  22. public async Task AddMessage(Room room, Message message)
  23. {
  24. room.Messages.Add(message);
  25. await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
  26. }
  27. public async Task<List<Room>> GetRoomsWhichSupportCreated(string supportId) =>
  28. await _dbCollection.Find(k => k.CreatedBy == supportId).ToListAsync();
  29. public async Task LeaveChatRoom(Room room, CustomerDTO userConnection)
  30. {
  31. room.Customers.Remove(userConnection);
  32. await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
  33. }
  34. }
  35. }