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

Activities of "sampath"

public async Task<int> CreatePropertyAsync(CreateOrEditPropertyInput input)
        {
            var property = input.Property.MapTo<Property>();
            var propertyId = await _propertyRepository.InsertAndGetIdAsync(property);
            return propertyId;
        }
public async Task<int?> EditPropertyAsync(CreateOrEditPropertyInput input)
        {
            var property = await _propertyRepository.FirstOrDefaultAsync(p => p.Id == input.Property.Id);
            input.Property.MapTo(property);
            await _propertyRepository.UpdateAsync(property);
            return input.Property.Id;
        }
public class CreateOrEditPropertyInput : IInputDto
    {
        [Required]
        public PropertyEditDto Property { get; set; }
    }
[AutoMap(typeof(Property))]
    public class PropertyEditDto
    {
        public const int MaxLength = 50;
        public int? Id { get; set; }
        public bool IsVacant { get; set; }
        public bool IsPropertyToConsider { get; set; }

        [Required]
        [MaxLength(MaxLength)]
        public string Dist { get; set; }

        [Required]
        [MaxLength(MaxLength)]
        public string Sec { get; set; }
  }

JS

vm.init = function () {
                propertyService.getPropertyForEdit({
                    id: vm.property.id
                }).success(function (result) {
                    vm.property = result.property;
                                    

                });
            };
public async Task<GetPropertyForEditOutput> GetPropertyForEdit(NullableIdInput<int> input)
        {
            var output = new GetPropertyForEditOutput();

            if (!input.Id.HasValue)//create
            {
                output.Property = new PropertyEditDto();
             }
            else //edit
            {
                var property = await _propertyRepository.FirstOrDefaultAsync(p => p.Id == input.Id.Value);
                output.Property = property.MapTo<PropertyEditDto>();
               
            }

            return output;
        }
public class GetPropertyForEditOutput : IOutputDto
    {
        public PropertyEditDto Property { get; set; }
       
    }

JS

//to save Property
            function createOrEditProperty() {
                vm.saving = true;
                propertyService.createOrEditPropertyAsync({ property: vm.property }).success(function (data) {
                    vm.property.id = data;
                    abp.notify.info(app.localize('SavedSuccessfully'));
                }).finally(function () {
                    vm.saving = false;
                });
            }

Q : Using above code snippets where I can "Create" and "Edit" the property correctly.App's UI is having many tabs and each and every tab is having "Save" button.Hence after creating the property where user can do any change again and can press the "Save" button again.The problem comes on that moment.It gives "An internal error occurred during your request!" error box when executes below line inside the "EditPropertyAsync()" method.This is the line :

input.Property.MapTo(property);

. Could you tell me why this is happening ? This is working fine when I use the "Edit" button.The problem occurs when I try to change the record after Creating it on the same screen without going to the "Edit" button.

Note : After creating the record,it returned the newly created property id back to the ui and by using that id where I decide it to be edited record.Then it executes "EditPropertyAsync()" method.That is the way I did it when user tries to use "Save" button again on the same screen without going to the Edit button. This time only it gives above mentioned error.

Note 2 : I have found out this from log file :

Source value:
0 ---> System.InvalidOperationException: The property 'Id' is part of the object's key information and cannot be modified.

Complete Exception :

ERROR 2015-11-19 10:38:16,338 [16   ] lers.Filters.AbpExceptionFilterAttribute - AutoMapper.AutoMapperMappingException: 

Mapping types:
Int32 -> Int32
System.Int32 -> System.Int32

Destination path:
Property.Address.Address.Id.Id

Source value:
0 ---> System.InvalidOperationException: The property 'Id' is part of the object's key information and cannot be modified. 
   at System.Data.Entity.Core.Objects.EntityEntry.VerifyEntityValueIsEditable(StateManagerTypeMetadata typeMetadata, Int32 ordinal, String memberName)
   at System.Data.Entity.Core.Objects.EntityEntry.GetAndValidateChangeMemberInfo(String entityMemberName, Object complexObject, String complexObjectMemberName, StateManagerTypeMetadata& typeMetadata, String& changingMemberName, Object& changingObject)
   at System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanging(String entityMemberName, Object complexObject, String complexObjectMemberName)
   at System.Data.Entity.Core.Objects.EntityEntry.EntityMemberChanging(String entityMemberName)
   at System.Data.Entity.Core.Objects.ObjectStateEntry.System.Data.Entity.Core.Objects.DataClasses.IEntityChangeTracker.EntityMemberChanging(String entityMemberName)
   at System.Data.Entity.DynamicProxies.Address_DC03C9817912E18A8FAA931110EEEF10FBB1519A7553CF5CAA7822ECD0C0FCBF.EntityMemberChanging(String )
   at System.Data.Entity.DynamicProxies.Address_DC03C9817912E18A8FAA931110EEEF10FBB1519A7553CF5CAA7822ECD0C0FCBF.set_Id(Int32 )
   at lambda_method(Closure , Object , Object )
   at AutoMapper.Internal.PropertyAccessor.SetValue(Object destination, Object value)
   at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.AssignValue(PropertyMap propertyMap, Object mappedObject, Object propertyValueToAssign)
   at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
   --- End of inner exception stack trace ---
   at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
   at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper)
   at AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper)
   at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
   at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.MapPropertyValue(ResolutionContext context, IMappingEngineRunner mapper, Object mappedObject, PropertyMap propertyMap)
   at AutoMapper.Mappers.TypeMapObjectMapperRegistry.PropertyMapMappingStrategy.Map(ResolutionContext context, IMappingEngineRunner mapper)
   at AutoMapper.Mappers.TypeMapMapper.Map(ResolutionContext context, IMappingEngineRunner mapper)
   at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
   at AutoMapper.MappingEngine.MapCore(Object source, Object destination, Type sourceType, Type destinationType, MappingOperationOptions options)
   at AutoMapper.MappingEngine.Map[TSource,TDestination](TSource source, TDestination destination, Action`1 opts)
   at AutoMapper.MappingEngine.Map[TSource,TDestination](TSource source, TDestination destination)
   at AutoMapper.Mapper.Map[TSource,TDestination](TSource source, TDestination destination)
   at Abp.AutoMapper.AutoMapExtensions.MapTo[TSource,TDestination](TSource source, TDestination destination)
   at Joshi.IP.IpProperties.PropertyAppService.&lt;EditPropertyAsync&gt;d__11.MoveNext() in d:\Freelance Work\Nipun-SPA\SPA\island\Joshi.IP.Application\IpProperties\PropertyAppService.cs:line 77
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Joshi.IP.IpProperties.PropertyAppService.<CreateOrEditPropertyAsync>d__5.MoveNext() in d:\Freelance Work\Nipun-SPA\SPA\island\Joshi.IP.Application\IpProperties\PropertyAppService.cs:line 52
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Threading.InternalAsyncHelper.&lt;AwaitTaskWithPostActionAndFinallyAndGetResult&gt;d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Threading.InternalAsyncHelper.&lt;AwaitTaskWithFinallyAndGetResult&gt;d__c`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Threading.Tasks.TaskHelpersExtensions.&lt;CastToObject&gt;d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Abp.Extensions.ExceptionExtensions.ReThrow(Exception exception)
   at Abp.WebApi.Controllers.Dynamic.Selectors.DynamicHttpActionDescriptor.<ExecuteAsync>b__0(Task`1 task)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ApiControllerActionInvoker.&lt;InvokeActionAsyncCore&gt;d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.AuthenticationFilterResult.&lt;ExecuteAsync&gt;d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()

Hi Halil,

Wow... Thanks a lot :)

I have above question due to I couldn't find out the drop down box which is having Material design UI features as shown below.Do I need to add any other references to get those effects ? But on text boxes where those having that effects.Hope you'll give feedback for this. Thanks in advance.

Material design drop down UI

<a class="postlink" href="https://material.angularjs.org/latest/demo/select">https://material.angularjs.org/latest/demo/select</a>

Thanks a lot Halil. It works :)

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

Yes.I saw that.Thanks a lot Halil :)

Could you tell me how to set the 1 : 1 relationship with the below mentioned models when we use the Asp.net Boiler plait ? Thanks in advance.

Note : I have seen this nice answer about the EF 1 to 1 relationship.But unfortunately I don't know how to set it with the Boiler plate.B'cos PK is automatically taken from the ABP.On my scenario where both tables having int PK.

SO : [url]http://stackoverflow.com/questions/6531671/what-does-principal-end-of-an-association-means-in-11-relationship-in-entity-fr

Note 2 : Here Property and Address models having 1 : 1 Relationship.

Property Model

[Table("IpProperties")]
    public class Property : FullAuditedEntity
    {

        public virtual bool Vacant { get; set; }

        public virtual Address Address { get; set; }

}

Address Model

[Table("IpAddresses")]
    public class Address : FullAuditedEntity
    {

        [Required]
        [MaxLength(MaxLength)]
        public virtual string StreetNumber { get; set; }

        public virtual Property Property { get; set; }
    }
Showing 181 to 187 of 187 entries