How is the first step to register Audit.Net in the "Startup.cs" of my application? - audit.net

Audit.Net
SomeBody can help me with one newbie question?
How is the first step to register Audit.Net in the "Startup.cs" of my application?
I'm try do audit with Entity FrameWrok focus one single table:
But i don't know waht is the NameSpace for this error?

That example is assuming you have an entity called AuditLog that is mapped to your single audit table.
You must create that entity if you don't have it already.
The table structure is up to you. You just tell the library how to map the different entities audits to your single audit entity.

Related

Easy Admin 3. How to use one CRUD Controller for to write to 2 entities

EasyAdmin 3 (Symfony)
Is it possible to use one CRUD Controller for write to one table and write some data to another table?
Your question is not really specific but you can override any CRUD action you want as cited in the documentation and persist data to other entities if you need to.
https://symfony.com/doc/current/EasyAdminBundle/crud.html#customizing-crud-actions

Edit Symfony entity from the frontend

I have a Symfony app using multiple entities.
A third-party analytic tool plugs to my database to create reportings.
What I would like to achieve, is being able to update the Symfony entity from the frontend in order to add new fields to the database tables (in order to get the new fields showing up in the reporting tool).
Anyone has a idea on how to achieve that?
Thanks in advance.
If i understand correctly, you wan't to be able to add fields to your entity dynamicaly.
I don't know if this is doable and if so, it would probably be messy and unsecure.
What you can do however is using sub-entities with dynamic key => values fields.
You should have one main entity, an entity with the list of your dynamic fields, a many to many relation between your main entity and your fields entities and a third entity with the actual values from those fields.

Add column to aspnetusers with database first

I have found many tutorials for adding columns to the Identity tables (which I have successfully moved to the application database) with database migrations however my understanding is this is not applicable in database fist projects. So...how do I add columns to the aspnetusers table in a database first project?
I would like to ad a bit type column called Is RegComplete which is initially set to 0 then at some point when the user has completed some more tasks then set to 1.
OK, I've cracked it! Firstly I didn't realise that although I have moved the Identity tables to the Application database there is still two Database Contexts, one for the application tables which are DB First, and the other for the Identities tables.
I was able to enable migrations and add the column using code first and migrate then update the database. The new column is now available in the controller.
I found this tutorial which helped me: http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx
The easiest solution:
Add columns into AspNetUsers table
Add properties into IdentityModels.cs class (Check attachment)
Add same properties into AccountViewModels.cs\RegisterViewModel class
Compile and it will work.
Attachment
(VS 2017, MVC5)

CakePHP model behaviors in Symfony2 + Doctrine2?

Is it possible to have behaviors in Symfony 2 entities, like in CakePHP? I'll try to explain what I need:
In some of my entities, I need to store who created or updated the record, when it was created or updated, at which company does it belongs and at which season does it belongs.
All these data is stored in the session, and I want to add it to the entity "magically", without adding these fields in the controller. With CakePHP I can create SeasonBehavior, mark some models/entities as they use the SeasonBehavior and when I persist a record from an entity marked with the SeasonBehavior the seasonId is updated.
Is it possible to do the same with Symfony2 and Doctrine 2? And if it's possible, do you know any tutorial or documentation explaining how to do this?
You need to create listener on your Persist action to do such things. Read the manual here: http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html

MVC3 Entity Framework using default membership relationships

I want to create a relationship between a custom table (Websites) and the default aspnet tables related to Users.
I'm using code-first so for most FK relationships I would just do
public ModelName ModelName { get; set; }
With this, EF will automatically create the FK relationships. Very easy.
What's confusing is the most effective way to hook into the aspnet users/membership table. Do I create a new model Users that acts as an interface so that I can implement custom user code?
Is there a best way to do this that fits well into EF best practices? I basically just want to relate a user to the Websites table/model so that EF can do its thing.
"Do I create a new model Users that acts as an interface so that I can implement custom user code?"
If you want flexibility, I would say this is the way to go. This way it would be easier if you wanted to change to some sort of different Authentication DB structure in the future.
For example, have an "AppUser" Entity where the corresponding table has a foreign key to the "UserID" column of the aspnet_Membership table. This way you can simply add properties to your "AppUser" Entity instead of trying to change the MS table structure (which can be a real pain). You can still interact with the built-in MS Membership classes and functions from your MVC project using something like the MvcMembership starter Kit DLL's.
https://github.com/TroyGoode/MembershipStarterKit
Hope this helps!
This has few preconditions:
ASP.NET tables must be in the same database as your own tables
Previous precondition means that you must either create your database and tables manually (without automatic code-first generation) or you must use some custom initializer which will add non mapped ASP.NET tables as part of database recreation
If you want your model class to have relation with ASP.NET table you must model ASP.NET table as another entity. I'm not sure if you can use ASP.NET classes for that because for example MembershipUser doesn't have parameterless public constructor which is required for EF. So you will most probably need to create duplicate classes and their mappings and use these classes when referencing ASP.NET entities.

Resources