0

In my ASP.NET MVC project I need to write code to check for users whether they accept terms and condition. I am using Entity framework and Database first approach. I have Table called Appterms, in which I have field called TermsAccepted and Date. I also have other fields in Appterms table such as GatewayUserId and termId. ' GatewayUserID has ID of registered users and termId is primary key. 'Termsaccepted' field is of bit type.

I tried to follow custom attribute function which is posted in this post MVC 3 How can I make a user view a warning/disclaimer screen but not able to implement as per my needs.

I am using this post Getting current user id to get id of current user. So after this how can i return 0 or 1 to check they accepted terms and condition.

This is the code snippet I am trying to use :

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, 
Inherited = true, AllowMultiple = false)]
public class AcceptedTermsCheck : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    // Check if AcceptedTC is set to true

    // If set, then do nothing

    // Otherwise redirect to TC page
    }
 }

Here to check if user accepted terms, i should return true, that is '1' in my GatewayUserId field, if not it should return false.But I don't know how to do this. And also I got to know I should create session to achieve this task. But never worked on it before.

Any help?? Thanks..

Community
  • 1
  • 1
Dev
  • 137
  • 1
  • 3
  • 15
  • I edited question and added source which i referred to solve this problem.But no success.. – Dev Aug 21 '13 at 11:40
  • The logic shown in the comments in your code should work. What are you currently having trouble with? – CodeCaster Aug 21 '13 at 13:16
  • You appear to have the right idea on how to do this - what is it you are having trouble with? – James Aug 21 '13 at 13:18
  • @CodeCaster My problem is till now i just figured it out the logic of this.But don't know how to implement. I am having problem in setting values in my database field, gatewayUserId 0 or 1 based on if it returns true or false. And also I am thinking do i need to use session to store user decision that is whether they accepted terms and condition. Will it make any sense to my problem?? – Dev Aug 21 '13 at 13:38
  • @james I posted my problem in previous comment.Can you have a look into that.. – Dev Aug 21 '13 at 13:39

2 Answers2

0

I think this is what you want to do. you can post back data or use jquery to post to a action to check and if the terms are accepted and then enable the submit button for a better user experience. Whichever way you choose, you can do something like this.

var dataEntityModel = new YoursEntities();
            AppTerm currentTerm = dataEntityModel.Appterms.ToList().
where(x=>x.GatewayUserId == yourCurrentUserID
&& x.termid == yourTermId).FirstOrDefault();

if(currentTerm.TermsAccepted == true)
{

}
else
{
   RedirectToAction("action","controller");
}
gurrawar
  • 363
  • 2
  • 8
  • 17
0
userlogin login = db.userlogins.Where(j => j.email == name && j.password == password && j.status == 1)
                               .FirstOrDefault();
Tunaki
  • 132,869
  • 46
  • 340
  • 423
samir
  • 396
  • 2
  • 13