Hello and thanks for reading this, could really use some help ;)
On my site, you play a puzzle after you entered your information and when you either complete the game before the time runs out or not your score will be posted into the gridview below.
I cant post a image but you can check the site if you want a good view about what I'm talking about Website
everything is working right now. you can play it and as you can see the time is showed. in the database that the information is stored in you every row has a unique ID.
here is my question - when someone hits "start spillet" and adds the information to the database, how can i get the unique ID that when that just been created and store it into a session so i can use it later.
(here is a row from my Database)
ID NAME EMAIL COLLEGE CLASS/TEAM TIME
114 Carsten TESTUSER#mediacollege.dk Technology h0dt100413 54
public string generateID()
{
return Guid.NewGuid().ToString("N");
}
using this function you will get a unique id and you can user it as session.
it will different every time
Related
Any walkthrough / sample code for ASP.Net (MVC Model) reflecting the way to record the current user's id in a table, and later on accessing only reflecting the said data?
For example a simple model for a SQL table recording sales being made by more than 1 selling officer at the same time, with fields like:
SalesDate
SalesAmount
SalesLocation
SalesOfficer (Automatically recording the user's id or relevant data)
Thus, the fourth field in the sample model above recording the user's id in the background so as to retrieve the same relevant data, when either logged-in by the same user or the administrator next time.
Hopefully, the question is simple and clear enough.
Looking forward for your expert advice, guidance and references in this regard.
Thanks in advance.
First of all what you can do is get data of SalesDate,
SalesAmount , SalesLocation in a model from a view. Now you need to know the Id of current logged in user.if you are using Default authentication in mvc you can get the currently logged in user by:
string id=System.Web.HttpContext.Current.User.Identity.GetUserId();
if not use appropriate method to get currently logged in user. After that you can add all the records in your database in your ActionMethod.
[HttpPost]
public ActionResult Create(SalesModel model)
{
tblSales sales=new tblSales();
sales.SalesDate=model.SalesDate;
sales.SalesAmount =model.SalesAmount;
sales.SalesLocation =model.SalesLocation;
sales.SalesOfficer =id; //This is the id of currently logged in user
_db.tblSales.Add(sales);
}
I am brand new to relational database manipulation with Visual C# as well as posting to StackOverflow. I have done every tutorial and read every word in the chapter on databases in Tony Gaddis' book Starting Out With Visual C#. As well as hours of googling and wading through walls of text and 20 minute tutorial videos.
I have created a database, connected it to the project and created a login form. All without a single line of code being written on my part.(The magic of "Visual" C#, eh?). The database has a table called Login with attributes called Email and Password. I am now trying to check the database for the Password WHERE Email is equal to the contents of the "Username" textbox and then compare those results to the contents of the "Password" textbox
This is my code for the Login button which I want to do what I described above:
private void btnLogin_Click(object sender, EventArgs e)
{
if (this.MaintenanceTableAdapter.GetPasswordByEmail(this.MaintenanceDataSet.Login, txtUsername.Text) == txtPassword.Text)
{
Main main = new Main();
main.Show();
}
}
GetPassWordByEmail is a method for a query I made in the MaintenanceDataSet.xsd file page. It asks for the row containing the Password where the Email column corresponds to the contents of a textbox called txtUsername.
I am getting errors under "MaintenanceTableAdapter" and "MaintenanceDataSet." I find this odd because in the tutorials when I would drag a DataGridView onto a form and then go over to the code I could use "TutorialTableAdapter" and "TutorialDataSet" to run queries just fine.
I'm very confused with all the talk I found while googling about TableAdapters and BindingSources so if you could explain like I'm 5 how those relate to what I'm doing here I'd be much obliged.
In fact if you could explain any part of this as if I were 5 that'd be great too:)
tl;dr do you know how I can query a database in C# to return a single row as a string and then compare that string to another string?
I will provide any more information you might need upon request. Thanks in advance!
I have a MS Access table which has a column called "recordLocked". Think of it as an editor. The contents is stored in the table and I have two users who want to edit the same content.
The system I have automatically "gives" the content to users to edit. So They log in and I have a timer which will ask the server (at random intervals) for content to edit.
Technically, two users logged on should NEVER request content from the server at the same time... yet they do. To the second. If I view logs, they say
"11:03:06 user 12 asked for content"
"11:03:06 user 77 asked for content"
When user 12 asks for the content, the c# code will update the record in the database to "locked" - so technically when user 77 asks for the content, it shouldn't give it to them (as it's locked).
But as they are asking at the same time, it's giving it to both of them.
Is there a better way to "lock" a record in this way? It's a YES/NO field which I query.
Thanks for any info!
You will want to look at record locking, which will lock a record (row) whilst it is being accessed/edited.
You can find how to implement this here: http://www.databasedev.co.uk/multi-user-application-record-locking.html
I want to verify that the user email is valid and turn this email into his id in my system.
Yet I don't know how to make a link in the mail, that activates the account like(facebook and others
) and I don't really understand what happens when the link is selected.
I thought of generating a key like "sdklbsdgk4493" to enter once- so that guessing is hard, yet for many people copy and paste is not trivial and I may annoy them with this solution.
Any thoughts or ideas?
p.s: I'm working in c# so if it can be done with c#... it will be great :)
Thanks Asaf
When you insert a new user in the Database, their status should be "Deactivated" and you insert a "GUID" you generate alongside. You send them a link to your activation Page which would contain this GUID in the Query String. It will look like this:
www.YourSite.com/Activation.aspx?GUID=jdfhg43h98234
In the Activation.aspx page, you take this GUID from the Query String and compare it to the one you have in the Database. You then activate the Account having that GUID.
Create the user
Generate a unique string for the user
Have a Table that stores the unique string, the user Id ,a boolean that holds whether it got activated or not, the generation date, the expiration date and if you have different uses for these activation strings, the type(link to another table)
Now within the email you should get the string and write it within the email along with a link to the page you're going to use for validation such as whatever.com/verify.aspx?activationString=hd3fd33fen342n43
Within this page you do a query search within the table that holds the keys and if its not already validated
You have your users table in the DB (or where ever it is that you store your list of users), just add a column stating if the user's mail is validated.
To the validation mail add a link that fires some PHP with a user-specific code (like it's index in the DB). The PHP will set the user's "validated" column to true, and it'll be done.
It's not as complicated as it may seem at first.
The idea is to create a random key, save it to the database connected to the useraccount, supplying a link to the users e-mail which could point to a webservice(or regular website) which takes the key as a querystring which will then activate the account connected to that specific key.
Im about to create a very simple online event reservation application and currently have 3 tables:
User
PK_UserID
UserName
Event
PK_EventID
EventName
EventDescription
EventStartDate
EventEndDate
SeatsAvailable
BookedEvents
ID
FK_UserID
FK_EventID
Do you have any experience of how to handle SeatsAvailable? I mean if SeatsAvailable is set to 5 and there are 5 users online and want to book event. And some user has started to fill out the form then changed his mind. Then seats in database can just leak. I was thinking about sessions - like to limit every user to 5 minutes to complete the booking but i dont really know if its good idea. Do you have any suggestions?
I dont really see your problem.
SeatsAvailable would be the total allowed seats, and the number of booked users would be the sum of the rows on BookedEvents.
in your procedure to enter a user to BookedEvents you would read the count of BookedEvents and SeatsAvailable in a transaction, if the event is full then the users gets a message saying the they are too late
am i missing something?
I would use your way as well, but I would reset the timeout everytime the booking is progressed (ie. new page). I know from experience you sometimes have to look something up or similar, and I really hate pages timing out in that case. You should be fine with a timeout.