Activities of "liangshiwei"

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));
            
        }
    }

Currently community is discussing how to configure foreign keys, Please following: https://github.com/abpframework/abp/issues/3959,

Hi, You can add Fluent Validators in the Application project and you can inject IStringLocalizer interface to return localized content .

Is this problem only on azure vm? Do you have this problem when deploying to a local IIS server?

Showing 5851 to 5860 of 5930 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11