添加命令数据验证和其他杂项修改
This commit is contained in:
@@ -14,9 +14,10 @@ namespace Infrastructure.EntityConfigurations
|
||||
public void Configure(EntityTypeBuilder<Link> builder)
|
||||
{
|
||||
builder.ToTable("Link");
|
||||
builder.HasKey(l => l.Id);
|
||||
builder.HasIndex(l => l.ShortCode).IsUnique();
|
||||
builder.Ignore(l => l.DomainEvents);
|
||||
builder.HasIndex(l => l.ShortCode).IsUnique();
|
||||
builder.HasKey(l => l.Id);
|
||||
builder.Property(l => l.Id).ValueGeneratedOnAdd().IsRequired();
|
||||
builder.Property(l => l.AppId).IsRequired();
|
||||
builder.Property(l => l.ShortCode).HasMaxLength(11);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Domain.AggregateModel.AppAggregate;
|
||||
using Domain.SeedWork;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,16 +11,31 @@ namespace Infrastructure.Repositories
|
||||
{
|
||||
public class AppRepository : IAppRepository
|
||||
{
|
||||
public IUnitOfWork UnitOfWork => throw new NotImplementedException();
|
||||
private readonly AppDbContext dbContext;
|
||||
|
||||
public void Add(App app)
|
||||
public AppRepository(AppDbContext dbContext)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
public Task<App> GetAsync(int id)
|
||||
public IUnitOfWork UnitOfWork => dbContext;
|
||||
|
||||
public App Add(App app)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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