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

RoomRepository.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. namespace Diligent.WebAPI.Business.Services
  7. {
  8. public class RoomRepository : BaseRepository<Room>, IRoomRepository
  9. {
  10. protected new IMongoCollection<Room> _dbCollection;
  11. public RoomRepository(IMongoDBContext context) : base(context)
  12. {
  13. _dbCollection = _mongoContext.GetCollection<Room>(typeof(Room).Name);
  14. }
  15. public async Task AddCustomerToRoom(Room room, string customerId)
  16. {
  17. room.Customers.Add(new CustomerDTO { CustomerId = customerId, DateOfEnteringRoom = DateTime.Now });
  18. await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
  19. }
  20. public async Task AddMessage(Room room, Message message)
  21. {
  22. room.Messages.Add(message);
  23. await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
  24. }
  25. public async Task<List<Room>> GetRoomsWhichSupportCreated(string supportId) =>
  26. await _dbCollection.Find(k => k.CreatedBy == supportId).ToListAsync();
  27. public async Task LeaveChatRoom(Room room, CustomerDTO userConnection)
  28. {
  29. room.Customers.Remove(userConnection);
  30. await _dbCollection.ReplaceOneAsync(x => x.Id == room.Id, room);
  31. }
  32. }
  33. }