2018-12-12 15:17:08 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using api.Models;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
namespace api.Data
|
|
|
|
{
|
|
|
|
public class UsersRepository : IUsersRepository
|
|
|
|
{
|
|
|
|
private readonly DataContext _context;
|
|
|
|
public UsersRepository(DataContext context)
|
|
|
|
{
|
|
|
|
this._context = context;
|
|
|
|
}
|
|
|
|
public void Add<T>(T enity) where T : class
|
|
|
|
{
|
|
|
|
_context.Add(enity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Delete<T>(T entity) where T : class
|
|
|
|
{
|
2019-02-21 00:09:38 +00:00
|
|
|
|
2018-12-12 15:17:08 +00:00
|
|
|
_context.Remove(entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<User> GetUser(int id)
|
|
|
|
{
|
|
|
|
var user = await _context.Users.Include(p=>p.Photos).FirstOrDefaultAsync(u=>u.Id==id);
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<User>> GetUsers()
|
|
|
|
{
|
|
|
|
var users= await _context.Users.Include(p=>p.Photos).ToListAsync();
|
|
|
|
|
|
|
|
return users;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<bool> SaveAll()
|
|
|
|
{
|
|
|
|
return await _context.SaveChangesAsync()>0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|