Click here to Skip to main content
13,894,768 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Good Day.

I have a MVC5 project using identity 2. I created a table named branch which stores 5 branch locations. The goal is to have the user select the branch he wants to log into, this will then be tagged to all their transactions. Once logged in the user will only be able to see transaction(theirs and others) corresponding to the branch he selected after initial authentication.


Could you point me to the right the resources that could be of benefit for this. Thanks

What I have tried:

I have extended the account model to include a foreign fey for a table called branch lookup this will then provide a many to many relationship to the table branches
Posted
Updated 1-Dec-18 19:03pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

So you've already tied to the user to the branch when they get registered into the User table that gets created in the identity framework right?

When you get a user (assuming you are using entity framework) you should be able to get the transaction id by an EF select statement (var user = users.Where(m=>m.username == "").select(m=>m.transactions);).

But to the main point of your issue.

I think, whatever data you are storing, you'll need to include the transaction guid/id from the user in the row being saved to the database.

To store the data, you could create an extension method on the IIdentity interface to get access to the transaction id tied to that user. Something like this

public static string GetTransactionId(this IIdentity identity)
        {
            var username = identity.GetUserName();
            var users = userstable.Where(m => m.UserName == username).Select(m => m.Transactions).FirstOrDefault;
            
            if (user == null)
            {
                return "";
            }

            var transId = users.TransactionId;
            return transId;
        }


Then the usage would simply be

User.Identity.GetTransactionId()


You'd be able to use this to get the transaction id and then save it to the table.

From there, in your controller/models you'd get the data from your DB by passing in the transcation id from the controller.

Something like

var transactionId = User.Identity.GetTransactionId();
var model = new MyDataModel();
model.Build(transactionId);


Then within your model you'd do something along the lines of

var mydatainmodel = tableindb.Where(m=>m.TransactionId == transactionIdPassedIn);


I may have mixed terminology between what you called "branch" and "transaction" but hopefully this steers you in the right direction.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190306.1 | Last Updated 2 Dec 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100