Activities of "liangshiwei"

Hi @roop.yekollu@atlasair.com

I use the project you provided, but can't reproduce this problem. Just one thing, you use automapper map object, but you did not initialize the collection in the parameterless constructor.null reference exception will be thrown when adding.

In addition, some boundary condition checks are missing in your code, like:

private async Task<bool> AddToSubEventsAsync(Alert alert, IEnumerable<string> subEvents)
{
    Check.NotNull(alert, nameof(alert));
    Check.NotNull(subEvents, nameof(subEvents));

    var EventTypesMasterList = await _eventTypeRepository.GetListAsync();

    foreach (var subEvent in subEvents)
    {
        var eventType = EventTypesMasterList.FirstOrDefault(e => e.Name == subEvent);
        alert.AddSubEvent(eventType.Id);  // If eventType object is null, you will get null reference exception.
    }

    return true;
}

Hi @roop.yekollu@atlasair.com

I suggest you delete the repository on github, because your commercial license is included in the project.

The cause of the error is not because of the AlertSubEventType entity, I think your code has wrong.

If you want to implement soft delete for AlertSubEventType entity, you should use b.HasIndex(ae => new { ae.EventTypeId, ae.AlertId }).HasFilter("[IsDeleted] != 1"); see https://github.com/abpframework/abp/issues/1181.

If you can provide a sample project that reproduce this problem, I can quickly help you find the problem.

I do n’t know much about FluentValidation, you can maybe inject repository to validator class and check duplicate entities. But I suggest you Check Duplicate Entities in the domain layer.

I see that you use alertRepository query in SetSubEventsAsync method,I don't know your implementation, I assume it queries from the database.so changes need to be saved.

var currentSubEventNames = await _alertRepository.GetSubEventTypes(alert);

I see that you call the RemoveFromSubEventsAsync method to delete the existing record, but the id value of the current alert entity is 0. I think you should make the following changes:

public virtual async Task<AlertDto> CreateAsync(AlertCreateDto input)
{
    var newAlert = new Alert()
    {
        Subject = input.Subject,
        FlightRegistrationNumber = input.FlightRegistrationNumber
    };

    var alert = await _alertRepository.InsertAsync(newAlert);

    await UpdateAlertByInput(alert, input);

    await CurrentUnitOfWork.SaveChangesAsync();
    return ObjectMapper.Map<Alert, AlertDto>(alert);
}

protected virtual async Task UpdateAlertByInput(Alert alert, AlertCreateOrUpdateDtoBase input)
{
    alert.Subject = input.Subject;
    alert.FlightRegistrationNumber = input.FlightRegistrationNumber;


    if (input.SubEventNames != null)
    {
        await SetSubEventsAsync(alert, input.SubEventNames);
    }
}

private async Task SetSubEventsAsync([NotNull] Alert alert, [NotNull] IEnumerable<string> subEventNames)
{
    Check.NotNull(alert, nameof(alert));
    Check.NotNull(subEventNames, nameof(subEventNames));

    if (alert.Id != 0)
    {
        await RemoveFromSubEventsAsync(alert);
    }

    await AddToSubEventsAsync(alert, subEventNames.Distinct());

}

private async Task<bool> RemoveFromSubEventsAsync(Alert alert)
{
    Check.NotNull(alert, nameof(alert));

    alert.SubEvents.Clear();

    return true;
}

private async Task<bool> AddToSubEventsAsync(Alert alert, IEnumerable<string> subEvents)
{
    Check.NotNull(alert, nameof(alert));
    var enumerable = subEvents as string[] ?? subEvents.ToArray();
    Check.NotNull(enumerable, nameof(subEvents));

    var EventTypesMasterList = await _alertEventTypeRepository.GetListAsync();

    foreach (var subEvent in enumerable)
    {
        var eventType = EventTypesMasterList.FirstOrDefault(e => e.Name == subEvent);
        alert.AddSubEvent(eventType.Id);
    }

    return true;
}

In addition, you configured a soft delete for the AlertSubEventType entity, but the entity uses a combined index, you need to remove soft delete:

 public class AlertSubEventType : Entity
{
    public long AlertId { get; set; }

    public int EventTypeId { get; set; }


    public AlertSubEventType()
    {
    }

    public AlertSubEventType(long alertId, int eventTypeId)
    {
        AlertId = alertId;
        EventTypeId = eventTypeId;
    }

    public override object[] GetKeys()
    {
        return new object[] {AlertId, EventTypeId};
    }
}

I tried to use your code, but did not reproduce the problem.

I didn't customize the alert repository for simplicity, After inserting the alert entity, I called the save change method of the unit of work, because the code you provided uses the repository to query the alert entity.

Hi

I have reproduced the problem. Abp module needs to add ~ for all static resource reference paths. but this way of referencing resources is currently not supported. Please following https://github.com/abpframework/abp/issues/3352. Actually I don’t recommend you to use sub-application deployment :)

So , How should I reproduce your problem, can you provide steps?

I mean using the AddSubEvent method of the Alert entity.

private async Task<bool> AddToSubEventsAsync(Alert alert, IEnumerable<string>subEvents)
{
    Check.NotNull(alert, nameof(alert));
    Check.NotNull(subEvents, nameof(subEvents));

    var EventTypesMasterList = await _alertEventTypeRepository.GetListAsync();

    foreach (var subEvent in subEvents)
    {
        var eventId = EventTypesMasterList.FirstOrDefault(e => e.Name == subEvent);
        alert.AddSubEvent(eventId);  // This line   
    }
    return true;
}

Try :

public class OrderDtoValidator:AbstractValidator<SupplierCombinedDto>
    {
        public OrderDtoValidator(IStringLocalizer<MyProjectResource> _localizer)
        {
            RuleFor(x => x.Customer).SetValidator(new CustomerDtoValidator(_localizer));
            RuleFor(x => x.Address).SetValidator(new AddressDtoValidator(_localizer));
            
        }
    }
Showing 5851 to 5860 of 5933 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11