mardi 11 avril 2017

Store current date and time in database using MVC

I have a requirement where I need to store the current system time in the database. here I need to provide 2 logins for User and Admin. Here User will login into the application and will click the In button. Then button action will trigger and will load the current system date and time and it will be saved in the database as well. same like Out button too. Below are the code works which I did,

This is my Model,
public class Employee
    {
        public DateTime In { get { return DateTime.Now; } }
        public DateTime Out { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
    }
}

This is My controller,
public ActionResult Login(Employee ED)
        {
            if (ModelState.IsValid)
            {
                var Admin = DE.tblEmployees.Where(m => m.Email.Equals(ED.Email) && m.Password.Equals(ED.Password)).Select(a => new { a.Role, a.Name, a.Email }).ToList();
                if (Admin != null)
                {
                    var role = Admin[0].Role;
                    ViewBag.Email = Admin[0].Email;

                    if (role == "Admin")
                        return RedirectToAction("AdminView", "Home");
                    else
                        return RedirectToAction("UserView", "Home");
                }
            }
            return View();
        }

This is My View,
        <button type="button">In</button>
        <button type="button">Out</button>

when you click In button then automatically current system date and time will save automatically.
How to achieve that functionality, how to write the code for this..
Any help would be grateful.

Aucun commentaire:

Enregistrer un commentaire