44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using Domain.AggregateModel.LinkAggregate;
|
|
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 LinkRepository : ILinkRepository
|
|
{
|
|
private AppDbContext dbContext;
|
|
|
|
public LinkRepository(AppDbContext dbContext)
|
|
{
|
|
this.dbContext = dbContext;
|
|
}
|
|
|
|
public IUnitOfWork UnitOfWork => dbContext;
|
|
|
|
public Link Add(Link link)
|
|
{
|
|
if (link.IsTransient())
|
|
{
|
|
return dbContext.Links.Add(link).Entity;
|
|
}
|
|
else
|
|
{
|
|
return link;
|
|
}
|
|
}
|
|
|
|
public async Task<Link> GetAsync(string shortCode)
|
|
{
|
|
var link = await dbContext.Links
|
|
.Where(l => l.ShortCode==shortCode)
|
|
.SingleOrDefaultAsync();
|
|
return link;
|
|
}
|
|
}
|
|
}
|