private static ManageContentPageService SetupManageContentPageService(
     ContentDbContext contentDbContext,
     IPersistenceHelper <ContentDbContext> contentPersistenceHelper = null,
     IContentService contentService = null,
     IMapper mapper = null,
     IReleaseFileService releaseFileService = null,
     IUserService userService = null)
 {
     return(new ManageContentPageService(
                mapper ?? MapperUtils.AdminMapper(),
                releaseFileService ?? new Mock <IReleaseFileService>().Object,
                contentService ?? new Mock <IContentService>().Object,
                contentPersistenceHelper ?? new PersistenceHelper <ContentDbContext>(contentDbContext),
                userService ?? MockUtils.AlwaysTrueUserService().Object
                ));
 }
Example #2
0
        public JsonResult ListarProdutos()
        {
            IRepositorio   repositorio = new Repositorio.Repositorio();
            List <Produto> produtos    = repositorio.SelecionarProdutos();
            List <ProdutoExibicaoViewModel> viewModel = new List <ProdutoExibicaoViewModel>();

            MapperUtils.MapearLista(produtos, viewModel);
            for (int i = 0; i < viewModel.Count; i++)
            {
                viewModel[i].Autor       = repositorio.SelecionarNomeAutor(produtos[i].IdAutor);
                viewModel[i].Editora     = repositorio.SelecionarNomeEditora(produtos[i].IdEditora);
                viewModel[i].ProdutoTipo = repositorio.SelecionarDescricaoProdutoTipo(produtos[i].IdProdutoTipo);
            }

            return(Json(new { data = viewModel }));
        }
Example #3
0
        public void CopyToList_CallsMapperWithContext_NullEntries()
        {
            var context = new object();
            var mapper  = new Mock <IMap <object> >();

            mapper.Setup(
                c => c.MapObject(It.IsAny <object>(), It.IsAny <object>(), It.IsAny <object>()))
            .Returns <object, object, object>((from, to, ctx) => from == null ? null : from.ToString());
            var destinationList = new List <string>();

            MapperUtils.CopyToList(new int?[] { 1, null, 3 }, destinationList, mapper.Object, context);

            mapper.Verify(c => c.MapObject(1, It.IsAny <object>(), context));
            mapper.Verify(c => c.MapObject(null, It.IsAny <object>(), context), Times.Never());
            mapper.Verify(c => c.MapObject(3, It.IsAny <object>(), context));
            Assert.AreEqual(new [] { "1", null, "3" }, destinationList.ToArray());
        }
Example #4
0
        public void GetThemes_PublicationHasNoReleases()
        {
            var builder = new DbContextOptionsBuilder <StatisticsDbContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var options = builder.Options;

            using (var context = new StatisticsDbContext(options, null))
            {
                var theme = new Theme
                {
                    Id    = Guid.NewGuid(),
                    Title = "Theme",
                    Slug  = "theme"
                };

                var topic = new Topic
                {
                    Id      = Guid.NewGuid(),
                    Title   = "Topic",
                    Slug    = "topic",
                    ThemeId = theme.Id
                };

                var publication = new Publication
                {
                    Id      = Guid.NewGuid(),
                    Title   = "Publication",
                    Slug    = "publication",
                    TopicId = topic.Id
                };

                context.Add(theme);
                context.Add(topic);
                context.Add(publication);

                context.SaveChanges();

                var service =
                    new ThemeMetaService(context, MapperUtils.MapperForProfile <DataServiceMappingProfiles>());
                Assert.Empty(service.GetThemes());
            }
        }
        private void ResolveRelations()
        {
            var dtos = MapperUtils.GetAllDtos();

            foreach (var dto in dtos)
            {
                var endpoint = dto.GetCustomAttributes().OfType <ApiEndpointAttribute>().FirstOrDefault();
                if (endpoint is null)
                {
                    continue;
                }
                var name = dto.BaseType.GetGenericArguments()[1].Name; //EntityTypeName
                _relations.Add(endpoint.Endpoint, new DtoRelation
                {
                    RelationColumnName = $"{name}Id",
                    DtoType            = dto
                });
            }
        }
Example #6
0
        public BaseSingleResponse <CfgProvideHelpPolicyDto> GetById(long id)
        {
            var response = new BaseSingleResponse <CfgProvideHelpPolicyDto>();

            try
            {
                CfgProvideHelpPolicy policy = SingleById(id);
                if (policy != null)
                {
                    CfgProvideHelpPolicyDto dto = MapperUtils.ConvertTo <CfgProvideHelpPolicy, CfgProvideHelpPolicyDto>(policy);
                    dto.NumberOfDaysTemp = policy.NumberOfDays.ToString();
                    dto.ProfitRateTemp   = policy.ProfitRate.ToString();

                    response.Value = dto;
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
            }
            return(response);
        }
Example #7
0
        public ApiBuilder AddDtoServices()
        {
            var dtos = MapperUtils.GetAllDtos();

            foreach (var type in dtos)
            {
                var iServiceType = typeof(IService <>).MakeGenericType(type);
                if (Services.Any(t => t.ServiceType == iServiceType))
                {
                    continue;
                }

                var interfaces = type.GetInterfaces().Where(t2 => t2.IsGenericType && t2.GetGenericTypeDefinition() == typeof(IDto <,>));
                foreach (var @interface in interfaces)
                {
                    var genericArguments = @interface.GetGenericArguments();
                    var genericService   = typeof(Service <,>).MakeGenericType(genericArguments[0], genericArguments[1]);
                    Services.AddScoped(iServiceType, genericService);
                }
            }
            return(this);
        }
Example #8
0
        private void ResolveDtoProjections()
        {
            var dtos = MapperUtils.GetAllDtos();

            foreach (var dto in dtos)
            {
                var projections = dto.GetInterfaces()
                                  .Select(t =>
                                          new ProjectionDefinition
                {
                    ProjectionType       = t,
                    Name                 = t.GetCustomAttribute <DtoProjectionAttribute>()?.ProjectionName,
                    ProjectionProperties = t.GetProperties().Select(p => p.Name)
                })
                                  .Where(t => t.Name != null);
                if (!projections.Any())
                {
                    continue;
                }
                DtoMetadata.Instance.Projections.Add(dto, projections);
            }
        }
Example #9
0
        /// <summary>
        ///  Set the transfer objects. We create the transfer object from the entity.
        /// </summary>
        /// <param name="reader">GridReader reader of dapper results</param>
        /// <param name="office">Poco to check if there is a null parameter.</param>
        private void SetDataTransferObject(SqlMapper.GridReader reader, SUBLICEN company, ref CompanyDto dto)
        {
            // think about the GridReader.

            if (reader == null)
            {
                return;
            }
            if (!string.IsNullOrEmpty(company.CP))
            {
                if (reader.IsConsumed)
                {
                    return;
                }
                Helper.CityDto = MapperUtils.GetMappedValue <POBLACIONES, CityDto>(reader.Read <POBLACIONES>().FirstOrDefault(), _mapper);
            }

            if (!string.IsNullOrEmpty(company.NACIO))
            {
                if (reader.IsConsumed)
                {
                    return;
                }

                Helper.CountryDto = MapperUtils.GetMappedValue <Country, CountryDto>(reader.Read <Country>().FirstOrDefault(), _mapper);
            }

            if (!string.IsNullOrEmpty(company.PROVINCIA))
            {
                if (reader.IsConsumed)
                {
                    return;
                }
                Helper.ProvinciaDto = MapperUtils.GetMappedValue <PROVINCIA, ProvinciaDto>(reader.Read <PROVINCIA>().FirstOrDefault(), _mapper);
            }
            var listOfOffices = reader.Read <OFICINAS>().ToList();

            dto.Offices = _mapper.Map <IEnumerable <OFICINAS>, IEnumerable <OfficeDtos> >(listOfOffices);
        }
Example #10
0
 public void Compile(CompilationContext context)
 {
     if (!(value is IAstRef) && !MapperUtils.IsNullable(value.itemType))
     {
         context.Emit(OpCodes.Ldc_I4_1);
     }
     else if (MapperUtils.IsNullable(value.itemType))
     {
         AstBuildHelper.ReadPropertyRV(
             new AstValueToAddr((IAstValue)value),
             value.itemType.GetProperty("HasValue")
             ).Compile(context);
         context.Emit(OpCodes.Ldc_I4_0);
         context.Emit(OpCodes.Ceq);
     }
     else
     {
         value.Compile(context);
         new AstConstantNull().Compile(context);
         context.Emit(OpCodes.Ceq);
     }
 }
Example #11
0
        public ApiBuilder AddDbContexts()
        {
            if (Options.ContextOption == null)
            {
                return(this);
            }
            var contexts = MapperUtils.GetAllContext();

            foreach (var context in contexts)
            {
                var builder = new DbContextOptionsBuilder();
                builder.UseLazyLoadingProxies();
                var lifetime        = context.GetCustomAttribute <ApiContext>()?.LifeTime ?? Enums.LifeTime.Transient;
                var serviceLifeTime = (ServiceLifetime)(int)lifetime;

                Services.Add(new ServiceDescriptor(context, p =>
                {
                    return(Activator.CreateInstance(context, Options.ContextOption(builder, p.GetService <IConfiguration>().GetConnectionString(context.Name)).Options));
                }, serviceLifeTime));
            }

            return(this);
        }
 public int Cadastrar(CandidatoVagaInclusaoVM entity) =>
 _service.Cadastrar(MapperUtils.Map <CandidatoVagaInclusaoVM, CandidatoVaga>(entity));
Example #13
0
 public IEnumerable <VagaConsultaVM> ObterTodos() =>
 MapperUtils.MapList <Vaga, VagaConsultaVM>(_service.ObterTodos());
Example #14
0
 public VagaConsultaVM ObterPorId(int id) =>
 MapperUtils.Map <Vaga, VagaConsultaVM>(_service.ObterPorId(id));
Example #15
0
 public IEnumerable <VagaConsultaVM> ObterPorTexto(string descricao) =>
 MapperUtils.MapList <Vaga, VagaConsultaVM>(_service.ObterPorTexto(descricao));
Example #16
0
 public bool Atualizar(VagaAlteracaoVM entity) =>
 _service.Atualizar(MapperUtils.Map <VagaAlteracaoVM, Vaga>(entity));
Example #17
0
 public int Cadastrar(VagaInclusaoVM entity) =>
 _service.Cadastrar(MapperUtils.Map <VagaInclusaoVM, Vaga>(entity));
Example #18
0
 public EmpresaConsultaVM ObterPorId(int id) =>
 MapperUtils.Map <Empresa, EmpresaConsultaVM>(_service.ObterPorId(id));
Example #19
0
 public IEnumerable <EmpresaConsultaVM> ObterTodos() =>
 MapperUtils.MapList <Empresa, EmpresaConsultaVM>(_service.ObterTodos());
Example #20
0
 public IEnumerable <EmpresaTecnologiaConsultaVM> ObterTodosPorTecnologia(int id) =>
 MapperUtils.MapList <EmpresaTecnologia, EmpresaTecnologiaConsultaVM>(_service.ObterTodosPorTecnologia(id));
Example #21
0
 public int Cadastrar(EmpresaInclusaoVM entity) =>
 _service.Cadastrar(MapperUtils.Map <EmpresaInclusaoVM, Empresa>(entity));
 public IEnumerable <HistoricoStatusConsultaVM> ObterTodosAgrupados() =>
 MapperUtils.MapList <HistoricoStatus, HistoricoStatusConsultaVM>(_service.ObterTodosAgrupados());
 public IEnumerable <HistoricoStatusConsultaVM> ObterPorDataStatus(DateTime dtInicial, DateTime dtFinal) =>
 MapperUtils.MapList <HistoricoStatus, HistoricoStatusConsultaVM>(_service.ObterPorDataStatus(dtInicial, dtFinal));
Example #24
0
 public IEnumerable <ProdutoConsultaVM> ObterTodos() =>
 MapperUtils.MapList <Produto, ProdutoConsultaVM>(_produtoService.ObterTodos());
Example #25
0
 public IEnumerable <ProdutoConsultaVM> ObterPorTexto(string texto) =>
 MapperUtils.MapList <Produto, ProdutoConsultaVM>(_produtoService.ObterPorTexto(texto));
Example #26
0
 public ProdutoConsultaVM ObterPorId(int idProduto) =>
 MapperUtils.Map <Produto, ProdutoConsultaVM>(_produtoService.ObterPorId(idProduto));
 public IEnumerable <HistoricoStatusConsultaVM> ObterPorIdStatus(int id) =>
 MapperUtils.MapList <HistoricoStatus, HistoricoStatusConsultaVM>(_service.ObterPorIdStatus(id));
 public IEnumerable <CandidatoVagaConsultaVM> ObterTodosPorVaga(int id) =>
 MapperUtils.MapList <CandidatoVaga, CandidatoVagaConsultaVM>(_service.ObterTodosPorVaga(id));
Example #29
0
        public override MapperAction <TContext> BuildAction <TFrom, TTo>(IMappingCollection <TFrom, TTo, TContext> map)
        {
            ExportMapInformation(map);

            MemberSetterAction <TContext> action = null;

            foreach (var iteratingSetter in map.Setters.Where(s => !s.IsIgnored))
            {
                var setter = iteratingSetter;
                if (setter.Remap)
                {
                    _mapper.RequireOneWayMap(setter.SourceType, setter.DestinationType, typeof(TFrom), typeof(TTo));
                }
                var toSetter   = setter.DestinationMember.CreateConstructingAccessorChain <TContext>(_mapper);
                var toAccessor = MapperUtils.CreateAccessorChain(setter.DestinationMember);
                switch (setter.SourceObjectType)
                {
                case MemberEntryType.Function:
                    var sourceFunc = (MapperAction <TContext>)setter.SourceFunc;
                    if (setter.Remap)
                    {
                        var remapper = _mapper.GetMapper(setter.SourceType, setter.DestinationType);
                        action += (from, to, context) => {
                            var dest = toAccessor.Get(to);
                            toSetter(to, remapper.MapObject(sourceFunc(from, to, context), dest, context), context);
                        };
                    }
                    else
                    {
                        action += (from, to, context) => toSetter(to, sourceFunc(from, to, context), context);
                    }
                    break;

                case MemberEntryType.Member:
                    var fromAccessor = MapperUtils.CreateAccessorChain(setter.SourceRoot.Union(setter.SourceMember));
                    if (setter.Remap)
                    {
                        var remapper = _mapper.GetMapper(setter.SourceType, setter.DestinationType);
                        action += (from, to, context) => toSetter(to, remapper.MapObject(fromAccessor.Get(from), toAccessor.Get(to), context), context);
                    }
                    else
                    {
                        action += (from, to, context) => toSetter(to, fromAccessor.Get(from), context);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException("MemberEntryType not supported");
                }
            }

            if (action == null)
            {
                return((from, to, context) => to);
            }
            else if (map.UpdatesContext)
            {
                return((from, to, context) =>
                {
                    if (to == null)
                    {
                        to = _mapper.ConstructOrThrow(typeof(TTo));
                    }
                    action(from, to, map.ContextUpdater(from, to, context));
                    return to;
                });
            }
            else
            {
                return((from, to, context) =>
                {
                    if (to == null)
                    {
                        to = _mapper.ConstructOrThrow(typeof(TTo));
                    }
                    action(from, to, context);
                    return to;
                });
            }
        }
Example #30
0
 public bool Atualizar(EmpresaAlteracaoVM entity) =>
 _service.Atualizar(MapperUtils.Map <EmpresaAlteracaoVM, Empresa>(entity));