I am having this error inside my [httpget] controller
usr.LastLoggedDate = HttpContext.Session.GetString("logg"));
cannot implicitly convert type string to system.datetime
I declared the http context set session inside the login controller
var dt = LastLoggedDate.ToString("MM/dd/yyyy");
HttpContext.Session.SetString("Logg", dt);
usr.LastLoggedDate = LastLoggedDate;
MY CODE
using DLFeed.Model;
using DLFeedback100.Repository;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Feed100.Controllers
{
public class UserDetailController : Controller
{
//UserDetailDataManagement objBL = new UserDetailDataManagement();
UserDetailDataManagement objBL = new UserDetailDataManagement();
public ActionResult Index()
{
return View();
}
[HttpGet]
public IActionResult Create()
{
UserDetail usr = new UserDetail();
// Get Session value.
usr.CreatedBy = HttpContext.Session.GetString("CurrUSerID");
usr.LastLoggedDate = HttpContext.Session.GetString("logg"));
if (usr.CreatedBy != null)
{
ViewBag.Info = usr.CreatedBy;
ViewBag.Enfo = usr.LastLoggedDate;
return View();
}
else
{
return RedirectToAction("Login");
}
return View();
}
[HttpPost]
public IActionResult Create(UserDetail usr)
{
//usr.CreatedBy = HttpContext.Session.SetString("CurrUSerID", usr.UserID);
if (ModelState.IsValid)
{
string msg = objBL.InsertUserDatail(usr);
if (msg == "success")
{
//ViewBag.SuccessMessage = " has been created successfully!"
return RedirectToAction("Create");
}
else
{
ViewBag.ErrorInfo = "Data not saved, try again latter";
}
}
return View();
}
public IActionResult Login()
{
return View();
}
[HttpPost]
public IActionResult login(string userID, string password, DateTime LastLoggedDate)
{
UserDetail usr = new UserDetail();
// Get Session value.
// usr.CreatedBy = HttpContext.Session.SetString("CurrUSerID", usr.UserID);
if (!ModelState.IsValid)
{
return View();
}
UserDetail erp = objBL.GetLogin(userID, password);
if (erp != null)
{
HttpContext.Session.SetString("CurrUSerID", userID);
usr.UserID = userID;
var dt = LastLoggedDate.ToString("MM/dd/yyyy");
HttpContext.Session.SetString("Logg", dt);
usr.LastLoggedDate = LastLoggedDate;
return RedirectToAction("Create");
}
else
// Invalid UserId Or Password.
ViewBag.Error = "Login failed";
return View();
}
}
}
PLEASE HELP ME