Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "OriAssurant"

This is how I intatiate the mapping call:

public string ManageOrder(DtoInputEntity inputEntity) { //this works Entity dto = new Entity(); dto = inputEntity.MapTo<Entity >();

        //this does not
         EntityLine dtoLine = new EntityLine();
          dtoLine = inputEntity.MapTo&lt;EntityLine &gt;();

}

is it because Shipment Number is being assigned against both Entity and EntityLine?

I am trying to map 2 complex object in CustomDtoMapper and unable to do it because the second mapping, does not seem to work.

Second Mapping to EntityLine from DtoInputEntity results in null values. none of the values get assigned.

Here is my CustomDtoMapper class:

internal static class CustomDtoMapper { private static volatile bool _mappedBefore; private static readonly object SyncObj = new object();

    public static void CreateMappings(IMapperConfigurationExpression mapper)
    {
        lock (SyncObj)
        {
            if (_mappedBefore)
            {
                return;
            }

            CreateMappingsInternal(mapper);              

            _mappedBefore = true;
        }
    }
          

    private static void CreateMappingsInternal(IMapperConfigurationExpression mapper)
    {
        mapper.CreateMap&lt;User, UserEditDto&gt;()
            .ForMember(dto => dto.Password, options => options.Ignore())
            .ReverseMap()
            .ForMember(user => user.Password, options => options.Ignore());
   
        
        mapper.CreateMap&lt;DtoInputEntity, Entity&gt;()
              .ForMember(entityCreateDto => entityCreateDto.OrderNumber,
                        dtoInputEntity => dtoInputEntity.MapFrom(input => input.Response.OrderNumber))
              .ForMember(entityCreateDto => entityCreateDto.ShipmentNumber,
                        dtoInputEntity => dtoInputEntity.MapFrom(input => input.Response.ShipmentNumber));
            
        mapper.CreateMap&lt;DtoInputEntity, EntityLine&gt;()
           .ForPath(entityLineCreateDto => entityLineCreateDto.ExternalModelIdentifier, opt => opt.MapFrom(dtoInputEntity => dtoInputEntity.Response.UTModelIdentifier))
           .ForPath(entityLineCreateDto => entityLineCreateDto.SKU, opt => opt.MapFrom(dtoInputEntity => dtoInputEntity.Response.ModelIdentifier))
           .ForPath(entityLineCreateDto => entityLineCreateDto.ShipmentNumber, opt => opt.MapFrom(dtoInputEntity => dtoInputEntity.Response.ShipmentNumber))
           .ForPath(entityLineCreateDto => entityLineCreateDto.LineNumber, opt => opt.MapFrom(dtoInputEntity => dtoInputEntity.Response.LineNumber));
        
    }
}

So, I fixed the mapper initializing issue using IObjectMapper. However, the mappings are not being invoked, because it is returning null after the objectMapper.Map<>().

This is what I have in PreInitialize of webApiModule: //Adding custom AutoMapper mappings Configuration.Modules.AbpAutoMapper().Configurators.Add(mapper => { TrackerMapper.CreateMappings(mapper); });

Is it because I'm configuring mappings in WebApiModule?

So, I took your suggestion to inject IObjectMapper to invoke the map as below: var transformedObject = _objectMapper.Map<Destination>(source);

It failed with the following error:

Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.

And I have removed all references to static Mapper.Map and replaced them with IObjectMapper reference.

Where can I override this to enable static mapper for my test module?

Does IObjectMapper support mapping of an object of one type to an object of an entirely different type? Why is it that the mappings from WebApiModule not initialized from TestModule class when I use DependsOn attribute?

<cite>aaron: </cite> ABP (and ASP.NET Zero) uses SweetAlert v2, not SweetAlert2 that has the showCloseButton option.

Thank you Aaron for the quick response. Hmm.. then it would be tough. is there a way to add the close button to the modal?

We're using AngularJS+MVC5.*. Is there a way to modify the abp.sweet-alert.js to show close button on the pop-up modal?

For example: swal({ title: "Are you sure?", text: "Test message?", type: "info", showCancelButton: true, focusConfirm: false, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes", cancelButtonText: "No", showCloseButton: true }, function (isConfirm) {})

Thank you :ugeek: !

This is the mapper class I have.

using Abp.AutoMapper; using Abp.Modules; using AutoMapper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace WebApi.TrackerService {

public static class TrackerMapper
{
    private static volatile bool _mappedBefore;
    private static readonly object SyncObj = new object();

    public static void CreateMappings(IMapperConfigurationExpression mapper)
    {
        lock (SyncObj)
        {
            if (_mappedBefore)
            {
                return;
            }

            CreateMappingsInternal(mapper);

            _mappedBefore = true;
        }
    }

    private static void CreateMappingsInternal(IMapperConfigurationExpression mapper)
    {
        mapper.CreateMap&lt;Source, Destination&gt;().ConvertUsing&lt;TrackerTypeConverter&gt;();            
       
    }

}

#region Mapping source to destination 

public class TrackerTypeConverter : ITypeConverter&lt;Source, Destination&gt;
{

    public Destination Convert(Source source, Destination destination, ResolutionContext context)
    {


        return
                new Destination
                {
                   //Transforming/mapping source to Destination
                };
    }

   

}
#endregion

}

I'm initializing CreateMappings from WebApiModule Initialize method as below: //Adding custom AutoMapper mappings Configuration.Modules.AbpAutoMapper().Configurators.Add(mapper => { TrackerMapper.CreateMappings(mapper); });

Invoking/using the mappings as below: var transformedRequest = Mapper.Map<Source, Destination>(request);

This works fine as a webApi project. But when I write my test cases, the mappings from my mapper class are not getting initialized.

In my test project, I added the attribute DependsOn[TypeOf(WebApiModule)] in TestModule class, but it doesn't seem to initialize the mappings from WebApiModule.

Thank you for your response in advance :) I greatly appreciate it.

I am using ITypeConvertor in the WebAPI project of Majestic. I had to add it as a dependency in the WebAPIModule class. Configuration.Modules.AbpAutoMapper().Configurators.Add(mapper => { TrackerMapper.CreateMappings(mapper); });

Now, I am trying to write test cases for the classes written in WebAPI project. But, I am getting this error during test cases:

The mapper initializations in webApi aren’t invoked from test module, as it is throwing the following error: System.InvalidOperationException : Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.

I have added the depends on attribute to the module as below. Which does not seem to help. Adding the tag DependsOn(typeof(MajesticWebApiModule) in TestModule class

Will appreciate inputs on why I am not able to using ITypeConvertor in the Test project.

Showing 111 to 120 of 152 entries