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

  • SEARCH
  • Home
  • 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 9157077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:55:30+00:00 2026-06-17T12:55:30+00:00

I have 3 action name delete on 3 different controllers which are on registration,profile

  • 0

I have 3 action name delete on 3 different controllers which are on “registration,profile and questions” they all have action delete methods. How can I from my registration-delete method call out profile-delete and questions-delete . That way when a user wants to delete their account all they have to do is go on registration-delete instead of going on registration,profile and questions delete methods. I want in 1 [HttpPost, ActionName(“Delete”)](registration) to call out the other 2 ActionName(“Delete”) methods as i prefer people to delete everything in one place is this possible? assuming that each user shares a unique ID that is the same all across. The comment in the code im just using to illustrate any help would be great

registration-delete below

  [HttpPost, ActionName("Delete")]
    public ActionResult DeleteConfirmed()
    {
        var ss = User.Identity.Name;
        var getid = (from s in db.registration where ss == s.email select s.RegistrationID).FirstOrDefault();
        registration registration = db.registration.Find(getid);
//This delete's the registration
        db.buyers.Remove(registration);

// How can i call-out profile-delete actionname here and questions-delete like
//if (question-delete != null){
// include  ActionResult deleteconfirmed("question-delete" }

        db.SaveChanges();
        return RedirectToAction("logout");
    }
  • 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-06-17T12:55:31+00:00Added an answer on June 17, 2026 at 12:55 pm

    If I understand your question, you are asking to call other controller’s action method from the currently executing action method? You typically would not do that. The first rule of Controller’s action methods is: no action method should be more than 10 lines of code. Basically, an action method is really supposed to be a simple method to collect a view, or call an action in your domain, and return.

    In other words, the SRP pattern:
    http://codebetter.com/karlseguin/2008/12/05/get-solid-single-responsibility-principle/

    Instead, you would organize your Domain-logic (what you describe is considered domain model logic, not controller logic) for this repetitive code such as deleting questions here, but when user is deleted also delete questions, etc.

    // an example of IOC injection of your IUserService
    private IUserService
    public RegistrationController(IUserService userService)
    {
        _userService = userService;
    }
    
    [HttpPost]
    public ActionResult Delete()
    {
    
        // insert modelstate and/or validation logic
        //
        if (User.Identity.IsAuthenticated == false)
        {
            return RedirectToAction("index", "Home");
        }
    
        // good practice to never bubble up exceptions to users
        try 
        {
            if (_userService.DeleteByEmail(User.Identity.Name) == false)
            {
                ModalState.AddModelError(String.Empty, "Not allowed?");
                return View();
            }
    
            // save it all in a single atomic operation here to keep it all in
            // a single Transaction Scope that will rollback properly if there is
            // an error.
            //
            db.SaveChanges();
        }
        catch (Exception)
        {
            ModalState.AddModelError(String.Empty, "An error occurred...");
            return View();
        }
    
        // all ok!
        return RedirectToAction("logout");
    }
    

    Notice how clean this action method is. It just gets down to business with a single line of code or two, and a whole bunch of exit paths to handle the user’s experience properly in many different situations.

    Now, your domain logic can be encapsulated into a service (or provider, or alike):

    namespace MyWebsite.Models
    {
    public class UserService : IUserService
    {
        // Todo: convert to some IoC lovin'
        //
    
        public Boolean DeleteByEmail(String email)
        {
    
            var user = 
                (from user in db.Registrations 
                 where 
                     user.Email == email
                 select s).FirstOrDefault();
    
             if (user == null)
                 return false;
    
             // call into other services to delete them
             ProfileDataService.DeleteByUserId(user.UserId);
             QuestionsService.DeleteByUserId(user.UserId);
    
             // finally, delete the user
             db.Registrations.Delete(user);
    
             // note, I am NOT calling db.SaveChanges() here.  Look
             // back at the controller method for the atomic operation.
             //
    
             return true;
        }
    }
    }
    

    This can be implemented 100s of different ways. The point being is to abstract that logic out to a common code base, or “Domain”. I chose to put that logic in your current Website namespace under Models as a shortcut in this example.

    As for your other Delete() methods on your other controllers, you would just call into a QuestionsService.DeleteByUserId() and ProfileDataService.DeleteByUserId() to handle those. You can even share those services across the domain, as I showed above.

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

Sidebar

Related Questions

I have an action for searching in NSMutableArray with name searcharray, which is equal
I have list page to show all images with its name from database in
I have a action on my controller (controller name is 'makemagic') called 'dosomething' that
I have an action that relies on User.Identity.Name to get the username of the
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left
I have a route: routes.MapRoute( Company, {id}/{name}.aspx, new { controller = Company, action =
Suppose I have the following expressions: Expression<Action<T, StringBuilder>> expr1 = (t, sb) => sb.Append(t.Name);
I would like to have 4 actions with the same name (controller methods may
Let say I have a screen name ITEM thats performs different actions: Save, Update,

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.