abpframework / abp

Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.31k stars 3.32k forks source link

Dynamic form and Audit Fields #571

Closed djlaney3 closed 5 years ago

djlaney3 commented 5 years ago

I am using a dynamic form that uses a Dto that implements AuditedEntityDto. When the form shows, it shows all the audit fields for input. Are those hideable? It seems that they should auto populate behind the scenes on save. Is this not how that works? Is that feature not available yet?

hikalkan commented 5 years ago

You should then separate your DTOs for "show data" and "save data". I mean you can create a DTO that is not derived from AuditedEntityDto and use it for the creation form.

djlaney3 commented 5 years ago

I changed my create/update dto to inherit from EntityDto and the dynamic form only shows my custom fields. But, on saving, the audit fields do not get updated. Should they? It seems like the framework does this automatically but I can't get it to work. So my underlying entity inherits from AuditedEntity, but the create/update dto inherits from AuditedEntityDto. Should this the audit fields auto populate?

hikalkan commented 5 years ago

Create/edit/update DTOs should not derive from audited DTOs. Auditing properties of the entity are automatically managed by the framework. Create properties set on creation, modification properties are set on update. Doesn't that work?

djlaney3 commented 5 years ago

It does seems to work for updates. For creates, my key is a bigint that auto increments. It appears the create dynamic form wants me to put in a value, but of course, the db won't accept it because it is the identity field. How do I set that up properly?

hikalkan commented 5 years ago

Your Id in the create form should not be required. If you want to use a single DTO for create/update, then make Id nullable (because it should not be set for creation - don't inherit from EntityDto in that case)

Why not getting Identity module as an example: https://github.com/abpframework/abp/tree/master/modules/identity

djlaney3 commented 5 years ago

Maybe I am mis understanding what you are saying. Here are my objects: CreateUpdateCareerDto.cs

[AutoMapTo(typeof(Career))]
    [AutoMapFrom(typeof(CareerDto))]
    public class CreateUpdateCareerDto : EntityDto<long>
    {
        [Required]
        [StringLength(50)]
        public string Name { get; set; }

        [StringLength(int.MaxValue)]
        public string Note { get; set; }
    }

Career.cs --entity

public class Career : AuditedEntity<long>
    {        
        [Required]
        [StringLength(50)]
        public string Name { get; set; }

        [StringLength(int.MaxValue)]
        public string Note { get; set; }
    }

The Id field shows up on both create and update.

djlaney3 commented 5 years ago

CareerDto

[AutoMapFrom(typeof(Career))]
    public class CareerDto : EntityDto<long>
    {
        public string Name { get; set; }

        public string Note { get; set; }
    }
acjh commented 5 years ago

Please format code like this:

```c#
// Your code
```
acjh commented 5 years ago

CreateUpdateCareerDto should not inherit EntityDto.

djlaney3 commented 5 years ago

Ok.. Made that change. Create works fine now. But update is not saving the LastModificationTime or LastModifierId columns. What am I doing wrong there? Previously I said it worked, but I was incorrect. The screen didn't error, but the db was not updated on the audit fields.

Also, CareerDto should inherit from EntityDto?

acjh commented 5 years ago
djlaney3 commented 5 years ago

LastModificationTime -> other than looking at the db field, how do I check properly?

acjh commented 5 years ago

Show code for updating.

djlaney3 commented 5 years ago

It is a dynamic form, the framework should handle it, shouldn't it?

yekalkan commented 5 years ago

[HiddentInput] attribute will hide the Id input box while you are editing the entity. See that example.

Other fields (CreationTime, LastModificatioTime etc.) shouldn't be there anyway.

djlaney3 commented 5 years ago

I'm not seeing how your comment is relevant to my issue. The audit fields are not present and shouldn't be on the edit forms. However, the LastModificationTime isn't being populated under any circumstance, and from what has been shown in this thread, it should be.

yekalkan commented 5 years ago

I am using a dynamic form that uses a Dto that implements AuditedEntityDto. When the form shows, it shows all the audit fields for input. Are those hideable?

And i just mentioned that dynamic-form will hide the fields that has [HiddentInput] attribute, if you're wondering.

djlaney3 commented 5 years ago

Ok. That can be useful. I'm still trying to figure out why the LastModificationTime won't populate though.

djlaney3 commented 5 years ago

I did another test using the BookStore sample app. It has the same issue. LastModificationTime does not populate on update.

hikalkan commented 5 years ago

@djlaney3 can you create an issue for "LastModificationTime does not populate on update".

djlaney3 commented 5 years ago

Opened new issue, #579. Closing this one.