42 lines
967 B
C#
42 lines
967 B
C#
using Domain.AggregateModel.AppAggregate;
|
|
using Domain.SeedWork;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Infrastructure.Repositories
|
|
{
|
|
public class AppRepository : IAppRepository
|
|
{
|
|
private readonly AppDbContext dbContext;
|
|
|
|
public AppRepository(AppDbContext dbContext)
|
|
{
|
|
this.dbContext = dbContext;
|
|
}
|
|
|
|
public IUnitOfWork UnitOfWork => dbContext;
|
|
|
|
public App Add(App app)
|
|
{
|
|
if (app.IsTransient())
|
|
{
|
|
return dbContext.Apps.Add(app).Entity;
|
|
}
|
|
else
|
|
{
|
|
return app;
|
|
}
|
|
}
|
|
|
|
public async Task<App> GetAsync(int id)
|
|
{
|
|
var app = await dbContext.Apps.Where(a => a.Id == id).SingleOrDefaultAsync();
|
|
return app;
|
|
}
|
|
}
|
|
}
|