using Diligent.WebAPI.Business.HelperModels; using Diligent.WebAPI.Business.MongoServices; using Diligent.WebAPI.Data; using Diligent.WebAPI.Data.Entities; using Microsoft.Extensions.Options; using MongoDB.Driver; namespace Diligent.WebAPI.Business.Services { public class RequestService : BaseMongo { public RequestService(IOptions webApiDatabaseSettings) : base(webApiDatabaseSettings, "Request") { } public async Task> GetRequestsAsync() => await _mongoCollection.Find(_ => true).ToListAsync(); public async Task GetRequestAsync(string id) => await _mongoCollection.Find(x => x.Id == id).FirstOrDefaultAsync(); public async Task CreateRequestAsync(Request req) => await _mongoCollection.InsertOneAsync(req); public async Task RemoveRequestAsync(string customerId,string roomId) { var request = await _mongoCollection.Find(x => x.SenderId == customerId && x.RoomId == roomId).FirstOrDefaultAsync(); if (request == null) return new DeleteCustomerRequest { IsSuccess = false }; var id = request.Id; _mongoCollection.DeleteOne(x => x.Id == request.Id); return new DeleteCustomerRequest { Id = id, IsSuccess = true }; } } }