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;
|
|
|
|
|
using System.Data.Entity;
|
|
|
|
|
|
|
|
|
|
using SharedLibrary.Interfaces;
|
|
|
|
|
using SharedLibrary.Database.Models;
|
|
|
|
|
using SharedLibrary.Database;
|
|
|
|
|
|
|
|
|
|
namespace SharedLibrary.Services
|
|
|
|
|
{
|
|
|
|
|
public class AliasService : IEntityService<EFAlias>
|
|
|
|
|
{
|
|
|
|
|
public async Task<EFAlias> Create(EFAlias entity)
|
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
throw 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;
|
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-02-07 00:19:06 -05:00
|
|
|
|
return await Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
using (var context = new DatabaseContext())
|
|
|
|
|
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)
|
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
using (var context = new DatabaseContext())
|
2017-11-25 20:29:58 -05:00
|
|
|
|
return await context.Aliases
|
2017-11-29 19:35:50 -05:00
|
|
|
|
.AsNoTracking()
|
2017-11-25 20:29:58 -05:00
|
|
|
|
.SingleOrDefaultAsync(e => e.AliasId == entityID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<EFAlias> GetUnique(string entityProperty)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EFAlias> Update(EFAlias entity)
|
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
throw new Exception();
|
|
|
|
|
using (var context = new DatabaseContext())
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
|
|
|
|
entity = context.Aliases.Attach(entity);
|
|
|
|
|
context.Entry(entity).State = EntityState.Modified;
|
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EFAliasLink> CreateLink(EFAliasLink link)
|
|
|
|
|
{
|
2017-11-29 19:35:50 -05:00
|
|
|
|
using (var context = new DatabaseContext())
|
2017-11-25 20:29:58 -05:00
|
|
|
|
{
|
|
|
|
|
context.AliasLinks.Add(link);
|
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|