public async Task <string> CreateLog(UsersLog usersLog) { try { await _context.UserLog.AddAsync(usersLog); await _context.SaveChangesAsync(); return("Success at creating log " + usersLog.ToString()); } catch (Exception ex) { return("Error at log " + usersLog.ToString()); } }
public ActionResult Authenticate(UsersLog user) { string result = ""; try { string pass = EncodePasswordMd5(user.Password); M_Users check = (from c in db.M_Users where c.UserName == user.UserName && c.Password == pass && c.IsDeleted == false select c).FirstOrDefault(); if (check != null) { bool rememberme = false; if (user.Rememberme) { rememberme = true; } System.Web.HttpContext.Current.Session["UserName"] = check.FirstName + ' ' + check.LastName; System.Web.HttpContext.Current.Session["user"] = check; FormsAuthentication.SetAuthCookie(user.UserName, true); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), rememberme, user.ToString()); } result = (check == null) ? "Failed" : "Success"; if (result == "Failed") { //Error_Logs error = new Error_Logs(); //error.PageModule = "Login"; //error.ErrorLog = "Incorrect Username or Password"; //error.DateLog = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;; //error.Username = user.UserName; //db.Error_Logs.Add(error); //db.SaveChanges(); } string urlmail = (Session["urlmail"] != null) ? Session["urlmail"].ToString() : "/Home/Index"; return(Json(new { result = result, urlmail = urlmail }, JsonRequestBehavior.AllowGet)); } catch (Exception err) { return(Json(new { result = result, urlmail = "" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Authenticate(UsersLog user) { string result = ""; db.Database.CommandTimeout = 0; try { string pass = EncodePasswordMd5(user.Password); M_Users check = (from c in db.M_Users where c.UserName == user.UserName && c.Password == pass && c.IsDeleted == false select c).FirstOrDefault(); check.CostCode = (from c in db.M_Employee_CostCenter where c.EmployNo == user.UserName orderby c.ID descending select c.CostCenter_AMS).FirstOrDefault(); string CostCodenow = check.CostCode; check.Section = (from c in db.M_Cost_Center_List where c.Cost_Center == CostCodenow select c.GroupSection).FirstOrDefault(); if (check != null) { bool rememberme = false; if (user.Rememberme) { rememberme = true; } string emailtemplatepath = Server.MapPath(@"~/Content/EmailForm/OTEmail.html"); System.Web.HttpContext.Current.Session["emailpath"] = emailtemplatepath; System.Web.HttpContext.Current.Session["UserName"] = check.FirstName + ' ' + check.LastName; System.Web.HttpContext.Current.Session["user"] = check; FormsAuthentication.SetAuthCookie(user.UserName, true); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), rememberme, user.ToString()); RefreshPageAccess(check.UserName, check.Section); List <CostCenterM> newCostCode = (from c in db.M_Cost_Center_List where c.GroupSection == "" || c.GroupSection == null select new CostCenterM { CostCodenew = c.Cost_Center, CostCodenewname = c.Section }).ToList(); System.Web.HttpContext.Current.Session["newCostCode"] = newCostCode; } result = (check == null) ? "Failed" : "Success"; if (result == "Failed") { //Error_Logs error = new Error_Logs(); //error.PageModule = "Login"; //error.ErrorLog = "Incorrect Username or Password"; //error.DateLog = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;; //error.Username = user.UserName; //db.Error_Logs.Add(error); //db.SaveChanges(); } string urlmail = (Session["urlmail"] != null) ? Session["urlmail"].ToString() : "/"; return(Json(new { result = result, urlmail = urlmail }, JsonRequestBehavior.AllowGet)); } catch (Exception err) { Error_Logs error = new Error_Logs(); error.PageModule = "Login"; error.ErrorLog = err.Message; error.DateLog = db.TT_GETTIME().FirstOrDefault();//DateTime.Now;; error.Username = user.UserName; db.Error_Logs.Add(error); db.SaveChanges(); return(Json(new { result = result, urlmail = "" }, JsonRequestBehavior.AllowGet)); } }