Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using MusicStore.Api.Business.Interface;
  4. using MusicStore.Data.Repository;
  5. using MusicStore.Entities;
  6. using MongoDB.Bson;
  7. using MusicStore.Data.Interface;
  8. using Microsoft.Extensions.Options;
  9. using MusicStore.Data.DBContext;
  10. using MongoDB.Bson.Serialization;
  11. using System;
  12. using Newtonsoft.Json;
  13. using System.Linq;
  14.  
  15. namespace MusicStore.Api.Business.Manager
  16. {
  17.     /// <summary>
  18.     /// This is custom repository for user collection
  19.     /// </summary>
  20.     public class UserManager : IUserManager
  21.     {
  22.         #region private variables
  23.         IGenericRepository<User> _dbRepository;
  24.         #endregion
  25.  
  26.         #region constructor
  27.         public UserManager(IDBManager<User> dbManager)
  28.         {
  29.             this._dbRepository = dbManager.Instance;
  30.         }
  31.         #endregion
  32.  
  33.         #region public methods
  34.         public async Task<IList<User>> GetAll()
  35.         {
  36.             return await this._dbRepository.GetAll();
  37.         }
  38.  
  39.         public async Task<User> GetById(string id)
  40.         {
  41.             return await this._dbRepository.GetById(id);
  42.         }
  43.  
  44.         public async Task<User> Insert(User user)
  45.         {
  46.             user._id = Guid.NewGuid();
  47.             await this._dbRepository.InsertAsync(user);
  48.  
  49.             return user;
  50.         }
  51.  
  52.         public Task<bool> Update(User user)
  53.         {
  54.             return _dbRepository.UpdateAsync(user);
  55.         }
  56.  
  57.         public Task<bool> DeleteById(string id)
  58.         {
  59.             return this._dbRepository.DeleteById(id);
  60.         }
  61.  
  62.         /// <summary>
  63.         /// Searches for a list of entities that match a key-value pair
  64.         /// </summary>
  65.         /// <param name="key">Property name</param>
  66.         /// <param name="value">Property value</param>
  67.         /// <returns></returns>
  68.         public async Task<IList<User>> SearchFor(string key, string value)
  69.         {
  70.             return await this._dbRepository.SearchFor(key, value);
  71.         }
  72.         #endregion
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement