Time Based Login [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In my .NET web application I need to implement time based Logins for students,The system should allow students to login only between 9 AM and 5 PM. somebody please suggest me how to implement this, which is better implementing using SQL time functions or using .net time methods?
If simply compare using normal time functions will it create when I host the application on a remote server(out side My country)?

Assuming that there are some users who are not students: (1) authenticate the user, (2) check the user's roles and if they are a student and attempting a login at naughty time then logout the user and display an appropriate message.
Using a single source for time in an application can reduce complications. I often use the database server as the source of time so that all timestamped data generated by the application can be correlated properly. UTC can be your friend in this case.

You can handle loggingIn event of login control and check if DateTime.Now lays between 9AM and 5PM
void OnLoggingIn(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
DateTime loginTime=DateTime.Now;
if (loginTime.Hour >= 9 && loginTime.Hour <= 17)
//log in your user
else
//show error message about time
}

Related

Is there a way to reserve a variable used by the operation in c#? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have this issue in my c# MVC App where i have a receipt and this receipt has a receipt number and i select the last receipt number inserted in the database and add 1 to it, the problem appears when 2 users submitting the receipt at the same time. What happens is that they both get the same receipt number and they both insert into the database, unfortunately one is inserted and the other gives exception and rollback the whole operation. So my question is there a way to prevent this from happening, in other words reserve a receipt number taken by user, so it won’t be used by the other user.
Thanks in advance.
If using sql server you should probably use an IDENTITY column. Another option would be to use a GUID as the key.
So you need to reset the receipt number for each new year? You could make a separate call to get the receipt number first without doing inserts into other tables. This would reserve a number and return immediately. You could use an identity column for this, either a separate table per year or reset the identity value and truncate at the start of each new year. Or you could have a table for Ids with Year and ReceiptNumber as the PK and insert a new row with incrementing receipt number by one.

Sending push notification to specific user using Facebook sid- Xamarin.Forms [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I build Xamarin.Forms App using this tutorial:
https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started
and I choose .NET back end.
I implement push notification for android and ios using this:
https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push
and also implement authentication using this: https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-users
while choosing Facebook as my authentication provider.
My app is running and working great! but now I trying to add push notification to a specific user and I have few questions:
Is it possible to use the Facebook sid as the unique id and decide that if I want to send push to a specific user, I will do this using the Facebook sid?
I read that when the user does the authentication through Facebook, his Facebook sid is register automatically has a unique id and I can send to this Facebook id as a TAG and it will arrived to the specific user.
In this line of code: var result = await hub.SendTemplateNotificationAsync(templateParams);
that is located in my .NET back end code in the " public async Task PostTodoItem(TodoItem item) " method, I tried to add a TAG after the "templateParams" , I tried to enter the Facebook sid or the Installation id, is this correct?
If I want to send to a specific user, is that the place that I need to add his "TAG"?
Am I going the right way? can I choose the TAG to be the unique id and when I want to send push to a specific user, I will send to his TAG?
I Wanted to know how the user is register to a specific TAG? if the approach from the second question is correct.
*If you have a written code or different approach, I would really like to hear, I trying to implement the push to specific user for about 2 weeks and still did not succeed.

Update a record in ASP .Net MVC [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Today in the interview I faced a question tat I had no clue about. Being a newbie into ASP .Net MVC I had no other way but to ask the experts about it.
"In your MVC Application ,data are being stored into a RDBMS System. In a .cshtml page ,there is a button to update the existing records into DB.
Now suppose two users from different parts of the Globe are at the same time are trying to update a common record. But by the the time the second user hits the submit button, you already submitted the update. In that case the second user , when would be pressing the submit won't be able to submit. Instead the page would reloaded for the second user with the updated info, discarding the changes.And then only he would be able to go on with the update"
How could you achieve that in ASP .Net MVC?
I though thought it might be something from the DB Side coding also , but I have no clue how to achieve the same.
You need to implement a strategy for managing concurrency. How you do this depends largely on the business rules of the application and the type of conflict that arises when two or more people attempt to change the same record.
Most often, you will add a column called RowVersion which will be a timestamp type. Whenever you display records to be updated, you also select the current RowVersion value and usually store it in a hidden field. The update operation will include the RowVersion field, which gets a new value, but before you commit an update operation, you compare the RowVersion value you have with the current one in the database. If they are different, someone else has updated the row during the time that it took you to get the record to be updated and then tried to change it. You determine how to proceed based on the application's business rules.
Asynchronous Tasks do the database operations , so even if another user tries to update , the first process runs in the background asynchronously

What's the most professional way for login control in ASP.NET? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Say, we are not using forms authentication or membership. When a user requests for any of the pages of the application, she needs to be redirected to login page.
This way, each page needs to have an authentication check on the Page_Load(). But what if we have over 500 pages.
Any chance to use sth like static classes with static properties or creating your own http handlers?
This is too broad of a question with a few aspects, including :
How to manage a User's Session
How to manage multiple user accounts being logged in
How to perform the login process
Managing a user's state must be independent of anyone else's actions. Therefor, you cannot rely on static properties. This presents the question of "Well, how do I keep track of it without it being static?" One of the answers is to use Session information. For example, during an Ajax request to the server you could do this :
if (HttpContext.Current.Session["LoggedIn"] != null)
{
object oValue = HttpContext.Current.Session["LoggedIn"];
bool bResult;
if (bool.TryParse((string)oValue, out bResult) == true)
return bResult
return false;
}
else
return false;
This solves the first two issues and opens a door to creating a hanlder class that knows YOUR specific session keys and patterns for getting different kinds of values.
As for the third issue you will face - No one can give you a concrete answer. Your design and data structure will determine how you validate and track your users.

How do I track a repeating calendar event in C# / SQL Server? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'd like to display a repeating event on a date/time display in an app. This date time display can take the form of a calendar, but it could also just be a list of upcoming events.
What is the best way to handle tracking this event that can repeat?
For example: Should the event be stored once in the database and projected out / repeated several times in the display code? Should the event be stored several times and then just rendered?
I did something like this before and I based my schema off of SQL Servers sysschedules table.
http://technet.microsoft.com/en-us/library/ms178644.aspx
The schema linked above will allow you to store the schedule for a job (event). Then you can calculate what dates the event occurs on based off of the schedule. This may be a lengthy calculation, so I would try to cache that result somewhere.
I think it depends on type of event it is. Is it like Christmas where once it comes along and happens you really aren't interested in it until the next occurrence? Or is it a task like, "Make sure I call my mom every month", where if it happens and you missed it you wouldn't want it to go away?
One way I recently implemented the latter was to have a record that had next_occurrence (date), reoccurence_period (weekly, monthly, yearly, etc) columns. So that as the next occurence approched it would show up in the list. Once it passed the list item would have a recycle icon that once pressed would update the record to the next future occurence.
Again, i'm not sure if this applies to your situation, but it worked well for mine.

Categories