public static ISpecification <TEntity> ToSpecification <TEntity>(this SpecificationDto specificationDto, ISpecification <TEntity> specification) where TEntity : class { foreach (Inflexion2.Application.Filter rule in specificationDto.CompositeFilter.Filters) { if (rule.Value != "") { if (specification == null) { specification = SpecificationsLinqExtensions.CreateSpecification <TEntity>(rule.Property, rule.Value, rule.Operator); } else { if (specificationDto.CompositeFilter.LogicalOperator == CompositeFilterLogicalOperator.And) { specification = specification.AndAlso(rule.Property, rule.Value, rule.Operator); } else { specification = specification.OrElse(rule.Property, rule.Value, rule.Operator); } } } } if (specification == null) { specification = new TrueSpecification <TEntity>(); } return(specification); }
private static void BuildSpecification(RadDataFilter dataFilter) { SpecificationDto specificationDto = GetFilter(dataFilter); specificationDto.CompositeFilter.Filters.Clear(); if (dataFilter.ViewModel.CompositeFilter.LogicalOperator == Telerik.Windows.Data.FilterCompositionLogicalOperator.And) { specificationDto.CompositeFilter.LogicalOperator = CompositeFilterLogicalOperator.And; } else { specificationDto.CompositeFilter.LogicalOperator = CompositeFilterLogicalOperator.Or; } foreach (FilterViewModel filter in dataFilter.ViewModel.CompositeFilter.Filters) { if (filter.SimpleFilter.Member != null) { var rule = new Filter() { Property = filter.SimpleFilter.Member, Operator = filter.SimpleFilter.Operator.ToString(), Value = filter.SimpleFilter.Value.ToString() }; specificationDto.CompositeFilter.Filters.Add(rule); } } }
public async Task <UserDto> UpdateSpecification(int id, SpecificationDto specificationDto) { var user = await GetByIdAsync(id); if (user == null) { return(null); } if (specificationDto.Height != null) { user.Height = (int)specificationDto.Height; } if (specificationDto.Weight != null) { user.Weight = (int)specificationDto.Weight; } _context.Update(user); await _context.SaveChangesAsync(); var dto = _mapper.Map <UserDto>(user); return(dto); }
// code generated from template "ServiceGetPaged.tt" /// <summary> /// Recupera una lista paginada de entidades Persona, según la especificación indicada. /// </summary> /// <param name="specificationDto"> /// Especificación que se va a aplicar. /// </param> /// <returns> /// La lista paginada de entidades 'Persona', según la especificación indicada. /// </returns> public PagedElements <PersonaDto> GetPaged(SpecificationDto specificationDto) { #region Preconditions // Comprobar el DTO de entrada. Guard.ArgumentIsNotNull( specificationDto, string.Format( FrameworkResource.EspecificationDataTransferObjectIsNull, "Persona")); #endregion List <PersonaDto> result = new List <PersonaDto>(0); int totalElements = 0; try { // Creamos el repositorio de la entidad. IPersonaRepository repo = ApplicationLayer.IocContainer.Resolve <IPersonaRepository>(); // Obtenemos las entidades aplicando la especificación. ISpecification <Persona> filter = specificationDto.ToSpecification <Persona>(); PagedElements <Persona> entities = repo.GetPagedElements( specificationDto.PageIndex, specificationDto.PageSize, filter.IsSatisfiedBy(), entity => entity.Id, true); totalElements = entities.TotalElements; // Mapeamos los datos. entities.ToList() .ForEach(entity => { var entityDto = this.personaMapper.EntityMapping(entity); result.Add(entityDto); }); // Confirmamos la transacción. this.Commit(); } catch (Exception ex) { throw ex; } // Devolver el resultado. return(new PagedElements <PersonaDto>(result, totalElements)); }
//PagedElements<Entity1Dto> GetPaged(SpecificationDto specificationDto, UserContextDto userContextDto); public PagedElements <EntityBDto> GetPaged(SpecificationDto specificationDto) { #region Preconditions // Comprobar el DTO de entrada. Guard.ArgumentIsNotNull( specificationDto, string.Format( Inflexion2.Resources.Framework.EspecificationDataTransferObjectIsNull, "Entity B")); //// usar un fichero de recursos para el dominio de negocio Company.Product.BoundedContext.Resources.Business.EntityBAlias #endregion List <EntityBDto> result = new List <EntityBDto>(0); int totalElements = 0; try { // Creamos el repositorio de la entidad. IEntityBRepository repo = this.unityContainer.Resolve <IEntityBRepository>(); // Obtenemos las entidades aplicando la especificación. ISpecification <EntityB> filter = specificationDto.ToSpecification <EntityB>(); PagedElements <EntityB> entities = repo.GetPagedElements( specificationDto.PageIndex, specificationDto.PageSize, filter.IsSatisfiedBy(), entity => entity.Id, true); totalElements = entities.TotalElements; // Mapeamos los datos. entities.ToList().ForEach(entity => { var entityDto = this.EntityBMapper.EntityMapping(entity); result.Add(entityDto); }); // Confirmamos la transacción. this.Commit(); } catch (Exception ex) { // Escribir en el Log. //logger.Error(ex.Message, ex); throw ex; } // Devolver el resultado. return(new PagedElements <EntityBDto>(result, totalElements)); }
private int AddSpecification(SpecificationDto specs, int ManufacturerId, string osType, int productAdd) { var specification = new Specification() { Id = productAdd, Camera = specs.Camera, Storage = specs.Storage, OSType = (SystemType)Enum.Parse(typeof(SystemType), osType), }; _dbContext.Specifications.Add(specification); _dbContext.SaveChanges(); return(specification.Id); }
public async Task <UserDto> UpdateSpecification(int id, SpecificationDto specificationDto) { if (specificationDto.Height == null && specificationDto.Weight == null) { _logger.LogInformation("Error while updating user specification"); throw new EmptySpecificationException(); } var user = await _userRepository.GetUser(id); if (user == null) { _logger.LogInformation("Error while updating user specification"); throw new UserNotFoundException(); } var result = await _userRepository.UpdateSpecification(id, specificationDto); return(result); }
//PagedElements<Entity1Dto> GetPaged(SpecificationDto specificationDto, UserContextDto userContextDto); public PagedElements <EntityADto> GetPaged(SpecificationDto specificationDto) { throw new System.NotImplementedException(); }
public static ISpecification <TEntity> ToSpecification <TEntity>(this SpecificationDto specificationDto) where TEntity : class { return(specificationDto.ToSpecification <TEntity>(null)); }
} // GetById /// <summary> /// Recupera una lista paginada de entidades Persona, según la especificación indicada. /// </summary> /// <param name="specificationDto"> /// Especificación que se va a aplicar. /// </param> /// <returns> /// La lista paginada de entidades Persona, según la especificación indicada. /// </returns> public PagedElements <PersonaDto> GetPaged(SpecificationDto specificationDto) { return(this.service.GetPaged(specificationDto)); }
public async Task <IActionResult> UpdateUsersDateOfBirth(int id, SpecificationDto specificationDto) { var result = await _userService.UpdateSpecification(id, specificationDto); return(Ok(result)); }
public static void SetFilter(RadDataFilter dataFilter, SpecificationDto value) { dataFilter.SetValue(FilterProperty, value); }