I am working on an ASP.NET MVC web portal that requires users to accept Terms of Use when they first log in. After the user clicks to accept, I need to pass back a bool (AcceptedTerms) as true. This value exists in the DB and there is a repository value (PortalUser.AcceptedTermsAndConditions) that will be used to push or pull the value from the DB. In the controller,
[ChildActionOnly]
public ActionResult RenderLogIn()
{
PortalUser portalUser = new PortalUser();
LogInViewModels model = new LogInViewModels() { AcceptedTerms = portalUser.AcceptedTermsAndConditions };
return PartialView("_LogIn", model);
}
Then in the model:
public class LogInViewModels
{
public bool AcceptedTerms { get; set; }
}
And in the view:
@if (Model.AcceptedTerms == false)
{
<script>
$("#TOUModal").modal('show');
function validateTerms() {
var valid = ($("#chkTOU").prop("checked"));
$("#submitTerms").prop("disabled", !valid);
}
$("#chkTOU").change(validateTerms);
$("#submitTerms").click(function () {
@Model.AcceptedTerms == true;
});
</script>
}
Lastly, I've got a repository method to update the value in the DB:
public void UpdateAcceptedTermsAndConditions( int UserID, Boolean Accepted )
{
VerifyConnectionString_LicensePortal();
SqlDataSource sqlDataSource = new SqlDataSource( ConnectionString_LicensePortal, "" );
String strSQLQuery = "UPDATE [dbo].[Users] SET [AcceptedTermsAndConditions] = @Accepted WHERE [UserId] = @UserID;";
sqlDataSource.UpdateCommand = strSQLQuery;
sqlDataSource.UpdateCommandType = SqlDataSourceCommandType.Text;
sqlDataSource.CancelSelectOnNullParameter = false;
sqlDataSource.UpdateParameters.Clear();
sqlDataSource.UpdateParameters.Add( "Accepted", DbType.Boolean, Accepted.ToString() );
sqlDataSource.UpdateParameters.Add( "UserID", DbType.Int32, UserID.ToString() );
sqlDataSource.Update();
}
How do I tie all of these things together so that upon login, I'm properly pulling in the DB value, and when the terms are accepted, the values gets updated in the DB?