| | 1 | | using Domain.Core.ValueObject; |
| | 2 | | using Domain.Entities; |
| | 3 | | using EasyCryptoSalt; |
| | 4 | | using Microsoft.EntityFrameworkCore; |
| | 5 | | using Repository.Abastractions; |
| | 6 | | using Repository.Persistency.Generic; |
| | 7 | |
|
| | 8 | | namespace Repository.Persistency.Implementations; |
| | 9 | | public class UsuarioRepositorioImpl : BaseRepository<Usuario>, IRepositorio<Usuario> |
| | 10 | | { |
| 24 | 11 | | public RegisterContext Context { get; } |
| | 12 | |
|
| 9 | 13 | | public UsuarioRepositorioImpl(RegisterContext context) : base(context) |
| 9 | 14 | | { |
| 9 | 15 | | Context = context; |
| 9 | 16 | | } |
| | 17 | |
|
| | 18 | | public override void Insert(Usuario entity) |
| 2 | 19 | | { |
| 2 | 20 | | var acesso = new Acesso(); |
| 2 | 21 | | acesso.Usuario = entity; |
| 2 | 22 | | acesso.CreateAccount(entity, Crypto.Instance.Encrypt("12345T!")); |
| 1 | 23 | | acesso.Usuario.PerfilUsuario = Context.Set<PerfilUsuario>().First(perfil => perfil.Id.Equals(acesso.Usuario.Perf |
| 14 | 24 | | acesso.Usuario.Categorias.ToList().ForEach(c => c.TipoCategoria = Context.Set<TipoCategoria>().First(tc => tc.Id |
| 1 | 25 | | Context.Add(acesso); |
| 1 | 26 | | Context.SaveChanges(); |
| 1 | 27 | | } |
| | 28 | |
|
| | 29 | | public override List<Usuario> GetAll() |
| 1 | 30 | | { |
| 1 | 31 | | return Context.Usuario.ToList(); |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | public override Usuario Get(Guid id) |
| 2 | 35 | | { |
| | 36 | |
|
| 2 | 37 | | return Context.Usuario |
| 2 | 38 | | .Include(u => u.PerfilUsuario) |
| 2 | 39 | | .Single(prop => prop.Id.Equals(id)); |
| 1 | 40 | | } |
| | 41 | |
|
| | 42 | | public override void Delete(Usuario obj) |
| 1 | 43 | | { |
| 1 | 44 | | var result = Context.Usuario.SingleOrDefault(prop => prop.Id.Equals(obj.Id)); |
| 1 | 45 | | result.StatusUsuario = StatusUsuario.Inativo; |
| 1 | 46 | | Context.Update(result); |
| 1 | 47 | | Context.SaveChanges(); |
| 1 | 48 | | } |
| | 49 | |
|
| | 50 | | public override bool Exists(Guid id) |
| 2 | 51 | | { |
| 2 | 52 | | return Context.Usuario.Any(prop => prop.Id.Equals(id)); |
| 2 | 53 | | } |
| | 54 | | } |