Hi support team,
I would like to change list page size according to some custom settings and depending on appservice call. Ex : appservice1 sends its result with a page size of 15 items by default appservice2 sends its result with a page size of 50 items by default
On server side, I see that DefaultPageSize is set to 10 (on AppConsts.cs). On client side (angular project), the value can be changed by user and stored within the browser ; so that, if user opens again a previous page, its list sized in setted to its previous value (different from 10).
What would you recommend to be able to change DefaultPageSize value according to appservice ?
Yes sure, here it is :
DTO's
public class GetEventsInput : PagedAndSortedInputDto, IShouldNormalize
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string Description { get; set; }
public void Normalize()
{
if (Sorting.IsNullOrWhiteSpace())
{
Sorting = "Begin DESC";
}
}
}
[AutoMapFrom(typeof(Event))]
public class EventListDto : FullAuditedEntityDto<long>
{
public long AddressId { get; set; }
public DateTime Begin { get; set; }
public DateTime End { get; set; }
public string Description { get; set; }
public long? MainUserId { get; set; }
public List<MainUserDto> EventUsers { get; set; }
}
[AutoMap(typeof(Event))]
public class EventEditDto : EntityDto<long>
{
[Required]
public DateTime Begin { get; set; }
[Required]
public DateTime End { get; set; }
public string Description { get; set; }
public List<MainUserDto> EventUsers { get; set; }
}
[AutoMap(typeof(Event))]
public class CreateEventInput
{
[Required]
public long AddressId { get; set; }
[Required]
public string Begin { get; set; }
[Required]
public string End { get; set; }
public string Description { get; set; }
public long? MainUserId { get; set; }
public List<MainUserDto> EventUsers { get; set; }
}
[AutoMap(typeof(User))]
public class MainUserDto : EntityDto<long>
{
public string Name { get; set; }
public string Surname { get; set; }
public string UserName { get; set; }
public string EmailAddress { get; set; }
public string PhoneNumber { get; set; }
public Guid? ProfilePictureId { get; set; }
}
And AppService's
[AbpAuthorize(AppPermissions.Pages_Tenant_Events_Create)]
public async Task CreateEvent(CreateEventInput input)
{
var eventVar = input.MapTo<Event>();
eventVar.EventUsers.Clear();
for (int i = 0; i < input.EventUsers.Count; i++)
{
eventVar.EventUsers.Add(await UserManager.GetUserByIdAsync(input.EventUsers[i].Id));
}
await _eventRepository.InsertAsync(eventVar);
}
public async Task<PagedResultDto<EventListDto>> GetEvents(GetEventsInput input)
{
var events = _eventRepository
.GetAll()
.Include(c=>c.EventUsers)
.Where(
p => (p.Begin >= input.StartDate &&
p.End <= input.EndDate)
);
var resultCount = await events.CountAsync();
var results = await events
.OrderBy(input.Sorting)
.PageBy(input)
.ToListAsync();
var eventListDtos = results.MapTo<List<EventListDto>>();
return new PagedResultDto<EventListDto>(resultCount, eventListDtos);
}
[AbpAuthorize(AppPermissions.Pages_Tenant_Events_Edit)]
public async Task<EventEditDto> GetEventEdit(EntityDto<long> input)
{
var _event = await _eventRepository.GetAll()
.Include(c => c.EventUsers)
.FirstAsync(c => c.Id == input.Id);
var _eventDto = _event.MapTo<EventEditDto>();
return _eventDto;
}
[AbpAuthorize(AppPermissions.Pages_Tenant_Events_Edit)]
public async Task UpdateEventEdit(EventEditDto input)
{
var _event = await _eventRepository.GetAsync(input.Id);
_event.EventUsers.Clear();
input.MapTo(_event);
await _eventRepository.UpdateAsync(_event);
}
Still having issues when updating entities : error log is " Validation failed for one or more entities". I've tried the same design with other entities that I've created (not with user entity from abp) and still having same issue for updates.
Hello support,
I have following issue :
I have added a collection to User entity like this :
/// <summary>
/// Represents a user in the system.
/// </summary>
public class User : AbpUser<User>
{
public const int MinPlainPasswordLength = 6;
public const int MaxPhoneNumberLength = 24;
public virtual Guid? ProfilePictureId { get; set; }
public virtual bool ShouldChangePasswordOnNextLogin { get; set; }
<span style="color:#FFFF00">public virtual ICollection<Event> Events { get; set; } </span>
As you can see, a collection of Event entities is added.
I also added a collection of User entity in Event entity like this :
[Table("LsEvents")]
public class Event : FullAuditedEntity<long>, IMustHaveTenant
{
public virtual int TenantId { get; set; }
[ForeignKey("AddressId")]
public virtual Address Address { get; set; }
public virtual long AddressId { get; set; }
[Required]
public virtual DateTime Begin { get; set; }
[Required]
public virtual DateTime End { get; set; }
public virtual string Description { get; set; }
public virtual ICollection<User> EventUsers { get; set; }
I've run the migrations on the database and everything went as excepted : foreign keys added to both table AbpUsers and LsEvents and an additional table UserEvents has been added automaticaly to manage many-to-many relationship.
Now, looking to the Event application service : I've created my DTO's to get, create and update Events. I am able to add a new event object with some Abp users as collection. No problem with this.
The problem is to update existing Event entities... When my Event DTO is received, the mapping is working well but User properties are being validated and following error is trhrown :
ERROR 2017-08-04 15:03:12,810 [8 ] EntityFramework.DbContext - There are some validation errors while saving changes in EntityFramework: ERROR 2017-08-04 15:03:12,810 [8 ] EntityFramework.DbContext - - Password: Le champ Password est requis.
Actually, I just want to update the link between Event and Users ... and not update each User entity !
Can you please provide a solution for that ?
Hello support,
I have following issue :
I have added a collection to User entity like this :
/// <summary>
/// Represents a user in the system.
/// </summary>
public class User : AbpUser<User>
{
public const int MinPlainPasswordLength = 6;
public const int MaxPhoneNumberLength = 24;
public virtual Guid? ProfilePictureId { get; set; }
public virtual bool ShouldChangePasswordOnNextLogin { get; set; }
<span style="color:#FFFF00">public virtual ICollection<Event> Events { get; set; } </span>
As you can see, a collection of Event entities is added.
I also added a collection of User entity in Event entity like this :
[Table("LsEvents")]
public class Event : FullAuditedEntity<long>, IMustHaveTenant
{
public virtual int TenantId { get; set; }
[ForeignKey("AddressId")]
public virtual Address Address { get; set; }
public virtual long AddressId { get; set; }
[Required]
public virtual DateTime Begin { get; set; }
[Required]
public virtual DateTime End { get; set; }
public virtual string Description { get; set; }
public virtual ICollection<User> EventUsers { get; set; }
I've run the migrations on the database and everything went as excepted : foreign keys added to both table AbpUsers and LsEvents and an additional table UserEvents has been added automaticaly to manage many-to-many relationship.
Now, looking to the Event application service : I've created my DTO's to get, create and update Events. I am able to add a new event object with some Abp users as collection. No problem with this.
The problem is to update existing Event entities... When my Event DTO is received, the mapping is working well but User properties are being validated and following error is trhrown :
ERROR 2017-08-04 15:03:12,810 [8 ] EntityFramework.DbContext - There are some validation errors while saving changes in EntityFramework: ERROR 2017-08-04 15:03:12,810 [8 ] EntityFramework.DbContext - - Password: Le champ Password est requis.
Actually, I just want to update the link between Event and Users ... and not update each User entity !
Can you please provide a solution for that ?
Hi,
I'm doing an ApplicationService. I would like to validate a DTO input according to some application settings. To do so, I implement ICustomValidate on my DTO class but I'm not able to get my setting value with SettingManager.GetSettingValueAsync...
Do you know how to proceed ?
If not possible, I could do a data validation directly on the ApplicationService before inserting data on the database... what is your advice ?
Thanks
Yes for sure, I'm extending AppComponentBase.
By digging on this issue this afternoon I found the problem : I used simple quotes instead of double. Now it's working.
This code doesn't work : <input class="form-control" type="text" name="DoorCode" <span style="color:#FF0000">placeholder="{{l("DoorCode")}}" </span>[(ngModel)]="address.doorCode" >
This one works well : <input class="form-control" type="text" name="DoorCode" <span style="color:#0040FF">placeholder='{{l("DoorCode")}}' </span>[(ngModel)]="address.doorCode" >
Thks for the hint. I will do so ;)
Hi,
I wanted to use the localization method inside my HTML template within an input object (angular2 project) . But, writing into placeholder property is not working : placeholder={{l("SomeID")}}
Any reason for that ?
Hi,
I have an issue when trying to update a collection inside an Entity. My entities are :
Address entity :
[Table("LsAddresses")]
public class Address : FullAuditedEntity<long>, IMustHaveTenant
{
public virtual int TenantId { get; set; }
[Required]
[MaxLength(ConstForLength.Name)]
public virtual string Name { get; set; }
[MaxLength(ConstForLength.DescriptionTitle)]
public virtual string Title { get; set; }
public virtual ICollection<PhoneAddress> Phones { get; set; }
}
PhoneAddress entity :
[Table("LsPhonesAddress")]
public class PhoneAddress : FullAuditedEntity<long>
{
[ForeignKey("AddressId")]
public virtual Address Address { get; set; }
public virtual long AddressId { get; set; }
[Required]
[MaxLength(ConstForLength.Number)]
public virtual string Number { get; set; }
}
I have created an interface with following DTO
[AutoMap(typeof(Address))]
public class AddressEditDto : EntityDto<long>
{
[Required]
[MaxLength(ConstForLength.Name)]
public string Name { get; set; }
[MaxLength(ConstForLength.DescriptionTitle)]
public string Title { get; set; }
public Collection<PhoneAddressInAddressListDto> Phones { get; set; }
}
[AutoMap(typeof(PhoneAddress))]
public class PhoneAddressInAddressListDto
{
public string Number { get; set; }
}
And my application service :
[AbpAuthorize(AppPermissions.Pages_Tenant_Addresses_Create)]
public async Task CreateAddress(AddressEditDto input)
{
var address = input.MapTo<Address>();
await _addressRepository.InsertAsync(address);
}
[AbpAuthorize(AppPermissions.Pages_Tenant_Addresses_Edit)]
public async Task<AddressEditDto> GetAddressEdit(EntityDto<long> input)
{
var address = await _addressRepository.GetAsync(input.Id);
return address.MapTo<AddressEditDto>();
}
[AbpAuthorize(AppPermissions.Pages_Tenant_Addresses_Edit)]
public async Task UpdateAddressEdit(AddressEditDto input)
{
var address = await _addressRepository.GetAsync(input.Id);
input.MapTo(address);
await _addressRepository.UpdateAsync(address);
}
In angular2 side, I'm able to create and get address entities with phones. But when I try to update an Address entity with a phone collection, I have foreign key exception on server side. Here is the exception from log :
System.InvalidOperationException: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted. à System.Data.Entity.Core.Objects.ObjectContext.PrepareToSaveChanges(SaveOptions options) à System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesInternalAsync>d__31.MoveNext()
I could remove collection from the DTO and have separated updates but I would like to fin a clean way to update collection inside an entity for other cases.
Any help is welcome ;)
Great ! Thanks for reactivity