public IEnumerable <TEntityDTO> GetAll(string[] includes = null) { using (var _dbContext = new FondoContext(_contextOptions)) { IEnumerable <TEntityDTO> returnable = null; try { var search = _dbContext.Set <TEntity>().AsNoTracking(); if (null != includes) { foreach (var item in includes) { search = search.Include <TEntity>(item); } } returnable = _mapper.Map <IEnumerable <TEntity>, IEnumerable <TEntityDTO> >(search.AsEnumerable()); } catch (AutoMapper.AutoMapperMappingException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(returnable); } }
public IEnumerable <TEntityDTO> Get(Func <TEntity, bool> filter, string[] includes = null) { using (var _dbContext = new FondoContext(_contextOptions)) { var _filter = filter; if (null != includes) { var search = _dbContext.Set <TEntity>().AsNoTracking(); foreach (var item in includes) { search = search.Include <TEntity>(item); } var xSearch = search.Where(_filter); return(_mapper.Map <IEnumerable <TEntity>, IEnumerable <TEntityDTO> >(xSearch.AsEnumerable())); } else { var search = _dbContext.Set <TEntity>().AsNoTracking().Where(_filter); return(_mapper.Map <IEnumerable <TEntity>, IEnumerable <TEntityDTO> >(search)); } } }
public async Task UpdateAsync(TEntityDTO entity) { using (var _dbContext = new FondoContext(_contextOptions)) { _dbContext.Set <TEntity>().Update(_mapper.Map <TEntityDTO, TEntity>(entity)); await _dbContext.SaveChangesAsync(); } }
public async Task <TEntityDTO> GetByIdAsync(int id) { using (var _dbContext = new FondoContext(_contextOptions)) { var search = await _dbContext.Set <TEntity>().FindAsync(id); return(_mapper.Map <TEntity, TEntityDTO>(search)); } }
/// <summary> /// Get the active Loan from an user /// </summary> /// <param name="personaId">Customer that has the active loan</param> /// <returns></returns> PrestamoDTO IPrestamoRepository.GetPrestamoActivoPersona(int personaId) { PrestamoDTO prestamo = null; using (var _dbContext = new FondoContext(_contextOptions)) { var prestamoActivo = _dbContext.Prestamo.AsNoTracking().Where(x => !x.Finalizado && x.PersonaId == personaId).Include(x => x.Consignaciones).FirstOrDefault(); if (null != prestamoActivo) { prestamo = _mapper.Map <Prestamo, PrestamoDTO>(prestamoActivo); } } return(prestamo); }
public async Task DeleteAsync(int id) { using (var _dbContext = new FondoContext(_contextOptions)) { var entity = await GetByIdAsync(id); if (null == entity) { throw new Exception("Element not found, can't delete"); } _dbContext.Set <TEntity>().Remove(_mapper.Map <TEntityDTO, TEntity>(entity)); await _dbContext.SaveChangesAsync(); } }
public List <KeyValuePair <string, string> > GetInteresSelectList() { var list = new List <KeyValuePair <string, string> >(); using (var _dbContext = new FondoContext(_contextOptions)) { var interesNoAfiliadoParam = _dbContext.Parametros.Where(x => x.Nombre == "Interes no afiliado").FirstOrDefault(); var interesAfiliadoParam = _dbContext.Parametros.Where(x => x.Nombre == "Interes Afiliado").FirstOrDefault(); list = new List <KeyValuePair <string, string> >(new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(key: "", value: "Seleccione ..."), new KeyValuePair <string, string>(interesNoAfiliadoParam.Id.ToString(), string.Format("{0} ({1}%)", interesNoAfiliadoParam.Nombre, interesNoAfiliadoParam.Valor1)), new KeyValuePair <string, string>(interesAfiliadoParam.Id.ToString(), string.Format("{0} ({1}%)", interesAfiliadoParam.Nombre, interesAfiliadoParam.Valor1)) }); } return(list); }
public string GetInteresPactado(int personaId) { string interesPactado = ""; using (var _dbContext = new FondoContext(_contextOptions)) { bool personaAfiliado = _dbContext.Persona.Where(x => x.Id == personaId && x.Afiliado).Count() > 0; if (personaAfiliado) { interesPactado = _dbContext.Parametros.Where(x => x.Nombre == "Interes Afiliado").FirstOrDefault().Valor1; } else { interesPactado = _dbContext.Parametros.Where(x => x.Nombre == "Interes no afiliado").FirstOrDefault().Valor1; } } return(interesPactado); }
IEnumerable <ConsignacionDTO> IConsignacionRepository.GetConsignaciones(int anhoParametrizado, string[] includes = null) { IEnumerable <ConsignacionDTO> returnable = null; using (var _dbContext = new FondoContext(_contextOptions)) { var search = _dbContext.Consignacion.Where(x => x.Fecha.Year == anhoParametrizado && ((x.Valor.HasValue && x.Valor.Value > 0) || (x.Interes.HasValue && x.Interes.Value > 0))); if (null != includes) { foreach (var item in includes) { search = search.Include <Consignacion>(item); } } returnable = _mapper.Map <IEnumerable <DAL.Consignacion>, IEnumerable <ConsignacionDTO> >(search.AsEnumerable()); } return(returnable); }
public async Task <TEntityDTO> GetByIdAsync(System.Linq.Expressions.Expression <System.Func <TEntity, bool> > filter, string[] includes = null) { using (var _dbContext = new FondoContext(_contextOptions)) { var _filter = filter; var search = _dbContext.Set <TEntity>().AsNoTracking(); if (null != includes) { foreach (var item in includes) { search = search.Include(item); } } var returnable = _mapper.Map <TEntity, TEntityDTO>(await search.FirstOrDefaultAsync(_filter)); return(returnable); } }
public List <KeyValuePair <string, string> > GetPersonasPrestamoActivoSelectList() { var list = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(key: "", value: "Seleccione ...") }; using (var _dbContext = new FondoContext(_contextOptions)) { var prestamosActivos = _dbContext.Prestamo.AsNoTracking().Where(x => !x.Finalizado).Include(x => x.Persona).ToList(); foreach (var item in prestamosActivos) { list.Add(new KeyValuePair <string, string>(item.PersonaId.ToString(), string.Format("{0} {1}", item.Persona.Nombres, item.Persona.Apellidos))); } } return(list); }