Base solution for your next web application
Open Closed

Angular 2 + Asp.net Core - missing creator userid #3336


User avatar
0
thobiasxp created

Hi,

Good Morning, While updating a table the creator userid is missing and updated creator userid as null and we have tried to add using full audited entity class but also same result creator userid is updated as null. Can you please provide us solution while updating table.

This is the method we have written for updating a table

public async Task UpdateCountry(CountryInputDto input) { var country = input.MapTo<Country>(); await _countryRepository.UpdateAsync(country); }

Input Class

[AutoMapTo(typeof(Country))] public class CountryInputDto { public int Id { get; set; } public virtual string CountryName { get; set; } public virtual string CountryCode { get; set; } }

Thanks


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you share Country entity as well ?

  • User Avatar
    0
    thobiasxp created

    Hi, Good Evening,

    [Table("Country")] public class Country : FullAuditedEntity { [Required] public virtual string CountryName { get; set; }

        [Required]
        public virtual string CountryCode { get; set; } 
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think you should first get country from _countryRepository, then map your input to it.

    var country = await _countryRepository.GetAsync(input.Id);
    ObjectMapper.Map(input, country);
    await _countryRepository.UpdateAsync(country);
    

    Otherwise, the fields not in CountryInputDto class will be null (or their default values) and you will also update fields not in your DTO.

    Thanks.

  • User Avatar
    0
    thobiasxp created

    Hi, Good Morning,

    Thanks for your help, it worked.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Great :)