| | 1 | | using Domain.Entities; |
| | 2 | | using Repository.Persistency.Generic; |
| | 3 | | using Microsoft.EntityFrameworkCore; |
| | 4 | | using Repository.Abastractions; |
| | 5 | | using System.Linq.Expressions; |
| | 6 | | using Domain.Core.ValueObject; |
| | 7 | |
|
| | 8 | | namespace Repository.Persistency.Implementations; |
| | 9 | | public class CategoriaRepositorioImpl : BaseRepository<Categoria>, IRepositorio<Categoria> |
| | 10 | | { |
| 12 | 11 | | public RegisterContext Context { get; } |
| 7 | 12 | | public CategoriaRepositorioImpl(RegisterContext context) : base(context) |
| 7 | 13 | | { |
| 7 | 14 | | Context = context; |
| 7 | 15 | | } |
| | 16 | |
|
| | 17 | | public override Categoria Get(Guid id) |
| 1 | 18 | | { |
| 1 | 19 | | return Context.Categoria.Include(d => d.TipoCategoria).Include(d => d.Usuario).FirstOrDefault(d => d.Id.Equals(i |
| 1 | 20 | | } |
| | 21 | |
|
| | 22 | | public override List<Categoria> GetAll() |
| 1 | 23 | | { |
| 1 | 24 | | return Context.Categoria.Include(d => d.TipoCategoria).Include(d => d.Usuario).ToList(); |
| 1 | 25 | | } |
| | 26 | |
|
| | 27 | | public override void Insert(Categoria entity) |
| 2 | 28 | | { |
| 2 | 29 | | var tipoCategoriaId = entity?.TipoCategoria?.Id; |
| 2 | 30 | | entity.TipoCategoria = Context.Set<TipoCategoria>().First(tc => tc.Id.Equals(tipoCategoriaId)); |
| 1 | 31 | | Context.Categoria.Add(entity); |
| 1 | 32 | | Context.SaveChanges(); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | public override void Update(Categoria entity) |
| 2 | 36 | | { |
| 2 | 37 | | var tipoCategoriaId = entity?.TipoCategoria?.Id; |
| 2 | 38 | | entity.TipoCategoria = Context.Set<TipoCategoria>().First(tc => tc.Id.Equals(tipoCategoriaId)); |
| 1 | 39 | | var existingEntity = Context.Categoria.Find(entity.Id) ?? throw new(); |
| 1 | 40 | | Context?.Entry(existingEntity).CurrentValues.SetValues(entity); |
| 1 | 41 | | Context?.SaveChanges(); |
| 1 | 42 | | } |
| | 43 | |
|
| | 44 | | public override IEnumerable<Categoria> Find(Expression<Func<Categoria, bool>> expression) |
| 1 | 45 | | { |
| 1 | 46 | | return Context.Categoria.Include(d => d.TipoCategoria).Include(d => d.Usuario).Where(expression); |
| 1 | 47 | | } |
| | 48 | |
|
| | 49 | | } |