53 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Blueprint.DAL.Infrastructure.Contracts;
 | |
| using Core.Blueprint.Domain.Entities;
 | |
| using Microsoft.Extensions.Logging;
 | |
| using MongoDB.Driver;
 | |
| 
 | |
| namespace Core.Blueprint.DAL.Infrastructure.Repository
 | |
| {
 | |
|     public sealed class BlueprintRepository: IBlueprintRepository
 | |
|     {
 | |
|         private readonly IMongoContext _context;
 | |
|         private readonly ILogger<BlueprintRepository> _logger;
 | |
|         private readonly IMongoCollection<BlueprintCollection> _collection;
 | |
| 
 | |
|         public BlueprintRepository(IMongoContext context, IProxyBlobStorage blobProxy, ILogger<BlueprintRepository> logger)
 | |
|         {
 | |
|             _context = context;
 | |
|             _logger = logger;
 | |
|             _collection = _context.Database.GetCollection<BlueprintCollection>("Blueprints");
 | |
|         }
 | |
| 
 | |
|         public async ValueTask<BlueprintCollection> GetByIdAsync(string id)
 | |
|         {
 | |
|             var result = await _collection.FindAsync(b => b.Id == id);
 | |
|             return result.First();
 | |
|         }
 | |
| 
 | |
|         async ValueTask<IQueryable<BlueprintCollection>> IRepositoryBase<BlueprintCollection>.GetAllAsync()
 | |
|         {
 | |
|             var result = await _collection.FindAsync(_ => true);
 | |
|             return (await result.ToListAsync()).AsQueryable();
 | |
|         }
 | |
| 
 | |
|         async ValueTask<BlueprintCollection> IRepositoryBase<BlueprintCollection>.CreateAsync(BlueprintCollection blueprint)
 | |
|         {
 | |
|             blueprint.Id = null;
 | |
|             await _collection.InsertOneAsync(blueprint);
 | |
|             return blueprint;
 | |
|         }
 | |
| 
 | |
|         public async Task<bool> UpdateAsync(string id, BlueprintCollection blueprint)
 | |
|         {
 | |
|             var result = await _collection.ReplaceOneAsync(b => b.Id == id, blueprint);
 | |
|             return result.IsAcknowledged && result.ModifiedCount > 0;
 | |
|         }
 | |
| 
 | |
|         public async Task<bool> DeleteAsync(string id)
 | |
|         {
 | |
|             var result = await _collection.DeleteOneAsync(b => b.Id == id);
 | |
|             return result.IsAcknowledged && result.DeletedCount > 0;
 | |
|         }
 | |
|     }
 | |
| }
 | 
