0
sampath created
Here I need to use same ui page for both creating and editing where I have tried as shown below. But it gives error when do the mapping here : var property = input.Property.MapTo<Property>(); inside the "CreatePropertyAsync()" method. Could you tell me where is the issue ? All primary keys are int type.Is that the problem on here : public int? Id { get; set; } in the " PropertyEditDto " object ? B'cos I have given it null-bale hence we don't have a "Id" key for the Create property scenario. Edit scenario we do have value for that.If it is the problem how can I do this ? Any help would be highly appreciated. Thanks in advance.
Mapping error is : Message "Missing type map configuration or unsupported mapping.\r\n\r\nMapping types:\r\nPropertyEditDto -> Property\r\.IP.IpProperties.Dtos.PropertyEditDto -> .IP.IpProperties.Property\r\n\r\nDestination path:\r\nProperty\r\n\r\nSource value:\r\.IP.IpProperties.Dtos.PropertyEditDto" string
PropertyAppService.cs
public async Task CreateOrUpdatePropertyAsync(CreateOrEditPropertyInput input)
{
if (input.Property.Id.HasValue)
{
await UpdatePropertyAsync(input);
}
else
{
await CreatePropertyAsync(input);
}
}
public async Task CreatePropertyAsync(CreateOrEditPropertyInput input)
{
var property = input.Property.MapTo<Property>();
await _propertyRepository.InsertAsync(property);
}
Dtos
public class CreateOrEditPropertyInput : IInputDto
{
[Required]
public PropertyEditDto Property { get; set; }
}
[AutoMapFrom(typeof(Property))]
public class PropertyEditDto
{
public const int MaxLength = 50;
public int? Id { get; set; }
[Required]
[MaxLength(MaxLength)]
public string Dist { get; set; }
[Required]
[MaxLength(MaxLength)]
public string Sec { get; set; }
[Required]
public DateTime DeedDate { get; set; }
[Required]
public decimal TransferTax { get; set; }
[Required]
public int CountyId { get; set; }
[Required]
public AddressDto Address { get; set; }
}
[AutoMapFrom(typeof(Address))]
public class AddressDto : FullAuditedEntityDto, IOutputDto
{
public string StreetNumber { get; set; }
public string StreetName { get; set; }
public int CityId { get; set; }
public CityListDto City { get; set; }
public int StateId { get; set; }
public StateListDto State { get; set; }
}
[AutoMapFrom(typeof(City))]
public class CityListDto : FullAuditedEntityDto
{
public string ZipCode { get; set; }
public string Name { get; set; }
}
[AutoMapFrom(typeof(State))]
public class StateListDto : FullAuditedEntityDto
{
public string Code { get; set; }
public string Name { get; set; }
}
Domain objects
[Table("IpProperties")]
public class Property : FullAuditedEntity
{
public const int MaxLength = 50;
[Required]
[MaxLength(MaxLength)]
public virtual string Dist { get; set; }
[Required]
[MaxLength(MaxLength)]
public virtual string Sec { get; set; }
[Required]
public virtual DateTime DeedDate { get; set; }
[Required]
public virtual decimal TransferTax { get; set; }
[ForeignKey("CountyId")]
public virtual County County { get; set; }
public virtual int CountyId { get; set; }
public virtual Address Address { get; set; }
[Table("IpCounties")]
public class County : FullAuditedEntity
{
public const int MaxLength = 50;
[Required]
[MaxLength(MaxLength)]
public virtual string Name { get; set; }
[Required]
[MaxLength(MaxLength)]
public virtual string State { get; set; }
public virtual ICollection<Property> Properties { get; set; }
}
[Table("IpCities")]
public class City : FullAuditedEntity
{
public const int MaxLength = 50;
[Required]
[MaxLength(MaxLength)]
public virtual string Name { get; set; }
[Required]
[MaxLength(MaxLength)]
public virtual string ZipCode { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
}
[Table("IpStates")]
public class State : FullAuditedEntity
{
public const int MaxLength = 50;
[Required]
[MaxLength(MaxLength)]
public virtual string Code { get; set; }
[Required]
[MaxLength(MaxLength)]
public virtual string Name { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
}