Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 626741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:27:06+00:00 2026-05-13T19:27:06+00:00

I am trying to follow the Nerd Dinner MVC application as a base to

  • 0

I am trying to follow the Nerd Dinner MVC application as a base to learn the correct way to develop MVC applications.

I have created Interfaces and Repositories as the reference code suggests and am using Entity Framework for data access.

If I want to insert data when a user registers into a table [dbo].[Users], I do not have a controller for Users, how do I do it?

AccountController.cs

[HandleError]
public class AccountController : BaseController
{
    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

            if (createStatus == MembershipCreateStatus.Success)
            {
                // TODO: Enter record into [Users] get reference to [Aspnet_UserId]
                // How do I do this??



                //FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", ErrorCodeToString(createStatus));
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }
}

If I create a UsersController to display views based on the Users table, how would I then add a new record when the user is registering?

I have a separate table [Users] that I wish to populate when a new user registers adding the [Aspnet_UserId] Guid.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:27:06+00:00Added an answer on May 13, 2026 at 7:27 pm

    You don’t need to have a controller for each table in your database. In the code above, the MembershipService is the code that is actually creating the record (via the Repository for users).

    The controllers should represent various areas and groups of functionality your website provides. While in many cases, you might have a controller with View, Create, and Update actions that do relate to a specific entity, that does relate to a specific database table, that isn’t and shouldn’t always be the case.

    If it makes sense to have a UsersController because you want to view a list of users, or a specific users profile, that’s fine, but the form for creating a user doesn’t have to be a part of that controller. Having it be a part of a membership, or admin, or account, or registration controller is ok too.

    Update
    I’ll try to provide you sample code of how I would expect the code to look. But you might have something else in mind, which is fine too, there’s no true single way to do these things.

    In your code above, I’m not sure what your MembershipService class is doing. It appears there is a static method on it that does something related to User Creation. I would expect that your MembershipService class should be calling your UserRepository to actually do the user creation. But you probably wouldn’t want a static class/method for this.

    public class MembershipCreationResult
    {
      public User Member { get; private set; }
      public MembershipCreateStatus MembershipCreateStatus { get; private set; }
    
      public MembershipCreationResult(User user, MembershipCreateStatus status)
      {
        Member = user;
        MembershipCreateStatus = status;
      }
    
      public bool Success
      {
        get { return MembershipCreateStatus == MembershipCreateStatus.Success; }
      }
    }
    
    public class MembershipService
    {
      public IUserRepository { get; private set; }
    
      public MembershipService(IUserRepository userRepository)
      {
        UserRepository = userRepository;
      }
    
      public MembershipCreateResult CreateUser(string name, string password, string email)
      {
        User member = UserRepository.Create(name, password, email);
        bool status = member != null ? MembershipCreateStatus.Success : MembershipCreateStatus.Failure;
    
        return new MembershipCreationResult(status, member)
      }
    }
    

    I haven’t taken a very close look at the NerdDinner sample, and I haven’t used the ASP.NET membership provider, but the concept I have outlined above should work. If MembershipService does something way different from what I have outlined, then you could create a new service to wrap the functionality and leave the existing MembershipService alone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn ASP.NET (since I know C#) so I have decided
I'm trying to follow a tutorial on setting up Spring MVC to work on
So I'm trying to follow this tutorial... to learn android, and I'm having a
I'm trying follow a tutorial to create a custom USB driver in Linux and
Trying to follow a technique found at bzr and gitosis I did the following:
I'm trying to follow a simple example of AJAX-enabled WCF Service like: http://www.pluralsight.com/community/blogs/fritz/archive/2008/01/31/50121.aspx I'm
I'm trying to follow code-to-interface on a project. Should I be creating an interface
I'm designing a new component to a system, trying to follow the various guidelines
I'm trying to create routes which follow the structure of a tree navigation system,
I am trying to replace multiple rows in an Access database to follow a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.