Display own records in grid view - asp.net

Im new to asp and i need u guys to guide me pls? Okay, lets just straight to the point. How to display current user who logged in to the system their own data? Like my system is about tracking expenses spent by user monthly. So, once user entered the expenses, prices for that particular month, it will be stored in db of course. But the tricky part here is when the user log in again, they should be able to view back their own records. So, basically i have a drop down menu which is used for month, Jan-Dec, grid view which to view all the particular user's records, view button (when user choose month,they click on the button and the grid view will show the expenses for that particular month) and thats all. So, if you guys have any idea, solution, pls tell me how. I would be appreciated if you could gimme the step by step to do that. Thank you.
|username|Month|Expense1|price 1| Expense2|Price2|....//this is the eg of my db structure
P/s: i dont know how to use HttpContext.Current.User.Identity.Name. If you could guide me by gimme the steps, that would be great! Thank you again.

Firstly, You must be having a Login form to login and view monthly expense and make new entries.
Now you can follow the below steps and make all your application working.
Assuming you have created the database to store new users information with there passwords and expenses table storing data related to the expense with respect to particular user after login.
Steps
once the user is logged in to your application. You can store the
User ID in Session.
This session can help you to take are which user is logged in or there are no users logged in currently to your application
since you have the database filled with all the details related to
expense. After login check if you have any user id in your session
or your session is null or not.
if you find any User ID session just pass this as a SqlParameter to your store Procedure and fetch all the records of this User id.
If you find any records bind your results to grid view. Otherwise display no records found and give a provision to Add new Expense Detail.
If you are using MemberShip API for Maintaining User Account and Login then you can user the HttpContext.Current.User.Identity.Name get the User ID from this name using MemberShip class in System.Web.Security namespace.
Hope the above steps are clear and you follow the functionality properly, to solve your problem.

Related

FOSUserBundle: How to know which users are online

I'm using FOS Rest Bundle and I'd like to show which users are online in the website. I don't know (I couldn't find any info about it) if there's a way to query the database and get if a user is currently online or not.
Is there a way to know this or any other bundle that could provide this info?
Thanks in advance
Add a "lastActivity" (datetime) attribute in your User class and use an event for update the date of this field everytime the user do an action on the site.
After that, just get all online user in last x minutes with a simple doctrine query on this field.

aspnet_user table for storing customer information

When regsitering in my site (ASP.Net MVC application), the users get inserted into the aspnet_users table. Since its a shopping site, I would want the users to have a customer id and all their details provided by them at registration in this Customer table as well. How do I link these 2 tables? Is it recommended to use the aspnet_user's UserId(Guid) in the application for other business processes.
Also, I would like to know when should a new record be inserted into the customers table.
I mean, when should a new customer be created. I guess its not good to create a record as ans when users are registered? Here, I want to know whats the norm? I felt it would be better to add it when a user adds an item to the shopping cart. Pls guide me.
Thanks in advance.
Add the UserId field into your customer table and then make a foreign key relationship back to the UserId in the aspnet_users table if you want to enforce relational integrity.
I'm not sure what you mean about when to insert the customer record. As long as you insert it after you have created the user (so that you have the user ID), you should be fine. It can happen in the same postback.
I'm not sure how you are saving the user. As in are you using one of the built-in ASP.Net controls or making the call manually?
If you are using the Membership provider as it sounds like you are, you can save the member using:
var user = Membership.CreateUser;
Guid userKey = user.ProviderUserKey;
//Populate your customer object.
//now use whatever EF/ADO/etc... to save your customer record.

"Role Management" vs "User Management" in ASP.NET

Question No 1
I am familiar with role management, a particular member in a particular role can do this and access this functionally. What I need to do is Manage individual user, not the role he is in.
For example, lets say I create a role, called "Sales". I setup the role permission what the sales persons can do. Now i want to keep a check on individual user. For example if this is "john", i want to show him the records only he created. If his is peter, I want to show him only that records which he created, not by john or other sales people.
Is there a thing called "User Management" in ASP.NET that we can use? If not we have to create it ourselves and I believe the integration with ASP.NET "Role Management" will not be that smooth.
Question No 2.
I am using control for user login. I want to create a session at this time so I can keep track of which user is signed in so I can show him the records only pertaining to him. How can I do that?
Your Q1 isn't really about Role vs User management (ie: authorizations) at this point. It's about audit tracking within your application.
And the way you do that is you capture the ID of the user who created the record in question with the record, so that later you can filter on that ID.
Pseudo database structure
Table Sales
Field...
Field...
Field...
CreatedByUser int not null, -- Populate this on creation and never change it again
ModifiedByUser int not null - populate this on every row update including insert
See ASP.NET Profile Properties.
Assuming the records in the database correspond to a unique ID for a user, you can store the unique id in a profile property per user.
1) If you want to filter records by the creating user, you need to record in your table the ID of the user who created the record. You can access the name of current user through User.Identity.Name and their ID (provider-dependent) through User.ProviderUserKey.
2) Sessions are created automatically in ASP.NET and provided you have a properly configured MembershipProvider, you can retrieve all the needed user info using the User object as shown above.
It sounds like you are a little unfamiliar with ASP.NET Membership and Roles capabilities, because they are actually set up quite well to accomplish what you are describing. I would recommend checking out this tutorial series:
https://web.archive.org/web/20211020202857/http://www.4guysfromrolla.com/articles/120705-1.aspx
You are talking about Authentication and Authorization. For question 1 you and implement a custom authorization provider to allow for user level control http://msdn.microsoft.com/en-us/library/aa479048.aspx For question 2, once you log in and are Authenticated, the session contains a userprinciple object that has the info in it automatically.

ASP.NET MVC, incrementing a value in the model's data every time a user clicks on a link

Essentially, this is what I have:
I have a view form for an object in MVC. On this form, I have a hyperlink. Every time that the user clicks the hyperlink, I would like an integer value inside of the object to increase by one, in addition to redirecting the user to a different page.
Is there a way to do this and keep track of how many times the link is clicked?
Thanks for any help that you can offer!
Yeah. Just have the link point to an MVC action that increments the value you want to increment before redirecting them to the action that they should actually go to.
Without more information, that's about as detailed as I can get.
The options are many. If it is one user then you could track this in any of the following: session, cookie, querystring, database or even LocalStorage.
If "the user" is just any user then cookies and LocalStorage are ruled out.
I'd imagine session is the easiest, assuming scale is not a major concern.
You have multiple options for this.
-> Save it in database
-> Session
-> increment value in the global variable

Drupal - Heartbeat activity - only showing activity wher a users is, the owner OR a member

Wondering if anyone knows how to create a view that only shows the activity of groups, where the current logged in user, is either the owner OR a member.
thanks :)
You can in views add an argument, and select the logged in user. You can use that to query whatever groups you are talking about.

Resources