Mouhssine tahri

Mouhssine tahri

  • NA
  • 201
  • 9.6k

insert in database information connection user (iduser ,date , time...

Mar 9 2021 11:28 AM
Hello,
 
i want if a user is connected in my web application some informations (IdUser,name date .. ) are insert in my table History in database sql server.
 
my class table:History.cs
  1. namespace GEC.DATA  
  2. {  
  3. using System;  
  4. using System.Collections.Generic;  
  5. public partial class History  
  6. {  
  7. public int HistoryID { getset; }  
  8. public string Description { getset; }  
  9. public string IpAddress { getset; }  
  10. public Nullable<System.DateTime> DateEvenement { getset; }  
  11. public Nullable<int> CodeUser { getset; }  
  12. public string Resultat { getset; }  
  13. public Nullable<System.DateTime> HeureEvenement { getset; }  
  14. }  
  15. }  
my controller:
  1. public class LoginController : Controller  
  2. {  
  3. [HttpPost]  
  4. public ActionResult Login(LoginViewModel loginViewModel, string returnUrl)  
  5. {  
  6. var Authentifie = HttpContext.User.Identity.IsAuthenticated;  
  7. ViewData["Authentifie"] = Authentifie;  
  8. if (ModelState.IsValid)  
  9. {  
  10. User user = usersDAL.VerifyCredential(loginViewModel.LogedUser.Login, loginViewModel.LogedUser.Password);  
  11. if (user != null)  
  12. {  
  13. FormsAuthentication.SetAuthCookie(user.UserID.ToString(), false);  
  14. if (!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))  
  15. return Redirect(returnUrl);  
  16. return Redirect("/");  
  17. }  
  18. ModelState.AddModelError("User.Login""Login et/ou mot de passe incorrect(s)");  
  19. }  
  20. return View(loginViewModel);  
  21. }  
  22. }  
my view Login.cshtml:
  1. <div class="login-body">  
  2. <div class="login-title"><strong>Bonjour</strong>, Connectez vous</div>  
  3. @using (Html.BeginForm(nullnullnew { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { id = "loginform" }))  
  4. {  
  5. <div class="form-horizontal">  
  6. <div class="form-group">  
  7. <div class="col-md-12">  
  8. @Html.EditorFor(model => model.LogedUser.Login, new { htmlAttributes = new { @class = "validate[required] form-control", placeholder = "Username" } })  
  9. @Html.ValidationMessageFor(model => model.LogedUser.Login, ""new { @class = "text-danger" })  
  10. @*<input type="text" class="form-control" placeholder="Username" />*@  
  11. </div>  
  12. </div>  
  13. <div class="form-group">  
  14. <div class="col-md-12">  
  15. @Html.PasswordFor(model => model.LogedUser.Password, new { @class = "validate[required] form-control", placeholder = "Password" })  
  16. @Html.ValidationMessageFor(model => model.LogedUser.Password, ""new { @class = "text-danger" })  
  17. @*<input type="text" class="form-control" placeholder="Password" />*@  
  18. <div class="profile-data-title" id="UserId"></div>  
  19. </div>  
  20. </div>  
  21. <div class="form-group">  
  22. <div class="col-md-6">  
  23. <a href="#" class="btn btn-link btn-block">Mot de passe oublié?</a>  
  24. </div>  
  25. <div class="col-md-6">  
  26. <button class="btn btn-info btn-block" id="LoginId" onclick="clicked();">Log In </button>  
  27. </div>  
  28. </div>  
  29. </div>  
  30. Html.EndForm();  
  31. }  
  32. </div>  
with this example authentification in my web app works goog , but what i want if i press button id="LoginId"
with event onclick I execute my javascript function clicked(); wich allows me to insert in my database
 
i want only how i can get information of authentificaion in my function javascript
 
thanks

Answers (2)