CRUD for user management with asp.net core mvc 2.0 - asp.net-core-mvc-2.0

I have managed to create CRUD controllers and views for each table/entity.
I have a problem with user table. This entity is a derivated class from IdentityUser.
I cannot insert or update this kind of entity.
What is the best way to make CRUD operations on this user table ?
Thanks

I do everything for users via the Microsoft.AspNetCore.Identity.UserManager class assuming you are using Identity.

Related

Storing information about users in other parts of the project

Using EF and Asp .Net Identity in an MVC 5 project. I would like to associate records in the database with particular users. The problem is, I have two separate DbContexts. ApplicationDbContext handles Identity functions: authentication, authorization, etc... My other DbContext (MyDbcontext) handles the actual business of the application. I would like to associate records in MyDbContext with users in ApplicationDbcontext. Do I need to open ApplicationDbContext, get my user info, close it, then open MyDbContext and perform some work? Can I open both at the same time? Do I need some kind of mapping table in MyDbcontext? For a bonus, can I get user info in my EF migrations seed method for MyDbContext?
You could have your app context inherit from identity context, but assuming you don't want to do that the next best option would be to configure a copy of the user model in your app context and add the DbSet<ApplicationUser> to your app context. You could also just store updatedBy and createdBy without doing a relation.

asp.net mvc with entity framework database first domain model validations

I'm Developing ASP.NET MVC Web Application project, and I'm using Entity Framework Database First Approach, So I would like to make validations on generated model classes, I know if i make validations on them directly, then my model validations will be overwritten every time my domain models are regenerated.
So I made a research, and found two approaches to use for this scenario:
1- Using buddy classes (How to add validation to my POCO(template) classes).
2- Using ViewModels and Auto-mapping them to my Entities (Designing an MVC repository using ViewModels
I see some sort of redundant code in these two methods, so, my question is:
Which one of the two approaches is best to flow?
1) This is the correct solution for adding validation metadata for the Entity Framework objects. The validation will be triggered automatically by EF before calling SaveChanges()
2) This is an aproach for creating Data Transfer Objects from your EF objects. You normally do this when you want to return the objects to the client (like in JSON format) - and you don't want to expose all the EF specific properties (like navigation properties, primary keys etc)

MVCScaffolding, Entity Framework Model First, many-to-many scaffolding

I am using Entity Framework Model First. There are 2 entities in my Model..
User
Role
I want to use MVC scaffolding (using VS 2012 or 2010) for this relationship.
From some posts in 20111 many-many was not supported. is it still not supported? If nto supported is there any workaround?
I can not change the Model (because database will be generated from it) however i am mainly looking forward creating Users, Creating Roles and Assigning roles to Users. if some workaround using one-many can give me above scaffolded views and controller I will be ok with that.
Thanks
Nachi

membership with custom table in asp.net mvc

I am trying to convert my vb.net 2010 web forms application into a C# MVC 4 application. Since my membership is already setup, I would prefer to just continue using the membership provider instead of the simplemembershipprovider.
Hi,
I am using PluralSight to learn MVC, but have not been able to find any reference on how to convert membership code to mvc.
I have a custom table that is linked by UserID to the mememberships User table. This custom table, asp_customUser, stores additional information about the user.
In the account controller, there is a register action, with the view and model. The register process does not handle roles, much less my custom data.
What I would like to know is, how do I add roles and custom user information to the database, when part of the fields in the registration view come from the membership library and the other part go to my custom table.
Thanks
Yes, you can use the old membership. Just copy and paste your membership provider from the old web.config to the new one.
If this is running on a different computer, you may need to set the machine key, however, in order for it to be able to correctly validate the password hashes.
You would then remove the Simple membership initialization attribute from the Account controller, and you would need to remove all the other simple membership code. You would also be giving up the OpenId authentication, because normal membership does not work with WebSecurity, so you would have to remove all that as well.
When we wanted to extend the membership class we inherited the base membership class and used all the fields in it and the tables linked to it and then create an additional database table with a FK linked to the id in the membership table. Any additional parameters where in the new table and extended class and any standard parameters were in the std membership table and standard class.

asp.net mvc editing Membership User data

What is the best approach to allow a user to change his email address?
im using the built in membership provider and AccountController. in asp.net mvc 3
My app is using Entity Framework but im not sure if its correct to add that membershipUser to the edmx and create a UsersController to do this... or add an action to accountController that handles this.
Please help
The membership provider has the ability to help you manage that. You would most likely add the ability into your AccountController to do this. I wouldn't add it into your EF classes. It is handled outside of your database anyway (unless you've written a custom MembershipProvider to talk to tables inside your database).
Take a look at this question too as it addresses some of what you may want to do and it includes source code.

Resources