2017-11-25 20:29:58 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
namespace SharedLibraryCore.Services
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
|
|
|
|
public class AliasService : IEntityService<EFAlias>
|
|
|
|
|
{
|
|
|
|
|
public async Task<EFAlias> Create(EFAlias entity)
|
|
|
|
|
{
|
2018-04-05 00:38:45 -04:00
|
|
|
|
throw await Task.FromResult(new Exception());
|
|
|
|
|
/*using (var context = new DatabaseContext())
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
var alias = new EFAlias()
|
|
|
|
|
{
|
|
|
|
|
Active = true,
|
|
|
|
|
DateAdded = DateTime.UtcNow,
|
|
|
|
|
IPAddress = entity.IPAddress,
|
|
|
|
|
Name = entity.Name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
entity.Link = await context.AliasLinks
|
|
|
|
|
.FirstAsync(a => a.AliasLinkId == entity.Link.AliasLinkId);
|
|
|
|
|
context.Aliases.Add(entity);
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await context.SaveChangesAsync();
|
2017-11-29 19:35:50 -05:00
|
|
|
|
return entity;
|
2018-04-05 00:38:45 -04:00
|
|
|
|
}*/
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<EFAlias> CreateProxy()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EFAlias> Delete(EFAlias entity)
|
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
using (var context = new DatabaseContext())
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
var alias = context.Aliases
|
|
|
|
|
.Single(e => e.AliasId == entity.AliasId);
|
|
|
|
|
alias.Active = false;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IList<EFAlias>> Find(Func<EFAlias, bool> expression)
|
|
|
|
|
{
|
2018-09-16 16:34:16 -04:00
|
|
|
|
// todo: max better?
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return await Task.Run(() =>
|
|
|
|
|
{
|
2018-09-16 16:34:16 -04:00
|
|
|
|
using (var context = new DatabaseContext(true))
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return context.Aliases
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.Include(a => a.Link.Children)
|
|
|
|
|
.Where(expression)
|
|
|
|
|
.ToList();
|
|
|
|
|
});
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EFAlias> Get(int entityID)
|
|
|
|
|
{
|
2018-09-16 16:34:16 -04:00
|
|
|
|
using (var context = new DatabaseContext(true))
|
2017-11-25 20:29:58 -05:00
|
|
|
|
return await context.Aliases
|
2018-09-16 16:34:16 -04:00
|
|
|
|
.FirstOrDefaultAsync(e => e.AliasId == entityID);
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 23:33:42 -05:00
|
|
|
|
public Task<EFAlias> GetUnique(long entityProperty)
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EFAlias> Update(EFAlias entity)
|
|
|
|
|
{
|
2018-04-05 00:38:45 -04:00
|
|
|
|
throw await Task.FromResult(new Exception());
|
2017-11-25 20:29:58 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|