添加命令数据验证和其他杂项修改
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Domain.AggregateModel.LinkAggregate;
|
||||
using Domain.SeedWork;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,16 +11,33 @@ namespace Infrastructure.Repositories
|
||||
{
|
||||
public class LinkRepository : ILinkRepository
|
||||
{
|
||||
public IUnitOfWork UnitOfWork => throw new NotImplementedException();
|
||||
private AppDbContext dbContext;
|
||||
|
||||
public void Add(Link link)
|
||||
public LinkRepository(AppDbContext dbContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
public Task<Link> GetAsync(string shortCode)
|
||||
public IUnitOfWork UnitOfWork => dbContext;
|
||||
|
||||
public Link Add(Link link)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user