mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using MyCore.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MongoDB.Driver;
|
|
|
|
namespace MyCore.Services
|
|
{
|
|
public class UserService
|
|
{
|
|
private readonly IMongoCollection<UserInfo> _Users;
|
|
|
|
public UserService(IConfiguration config)
|
|
{
|
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
|
var database = client.GetDatabase("MyCoreDb");
|
|
_Users = database.GetCollection<UserInfo>("Users");
|
|
}
|
|
public List<UserInfo> GetUsers()
|
|
{
|
|
return _Users.Find(m => true).ToList();
|
|
}
|
|
|
|
public UserInfo GetUserByEmail(string email)
|
|
{
|
|
return _Users.Find<UserInfo>(m => m.Email == email).FirstOrDefault();
|
|
}
|
|
|
|
public UserInfo GetUserById(string id)
|
|
{
|
|
return _Users.Find<UserInfo>(m => m.Id == id).FirstOrDefault();
|
|
}
|
|
|
|
public UserInfo CreateUser(UserInfo user)
|
|
{
|
|
_Users.InsertOne(user);
|
|
return user;
|
|
}
|
|
|
|
public UserInfo Update(string id, UserInfo userIn)
|
|
{
|
|
_Users.ReplaceOne(user => user.Id == id, userIn);
|
|
return userIn;
|
|
}
|
|
|
|
public void Remove(string id)
|
|
{
|
|
_Users.DeleteOne(user => user.Id == id);
|
|
}
|
|
|
|
}
|
|
}
|