public bool InsertLog(LogHistoryModel model)
        {
            try
            {
                if (model == null)
                {
                    return(false);
                }
                using (var db = new PORTALEntities())
                {
                    var obj = new SysLogHistory
                    {
                        UserId          = model.UserId,
                        IpAddress       = model.IpAddress,
                        LogTime         = DateTime.Now,
                        OperatingSystem = model.OperatingSystem,
                        PcName          = model.PcName,
                        PcBrowser       = model.PcBrowser,
                        //ControllerName = model.ControllerName,
                        //ActionName = model.ActionName
                    };
                    db.SysLogHistories.Add(obj);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("Log Repository Insert Log: " + ex.Message + " Inner exception: " + ex.InnerException.Message);
                return(false);
            }
        }
Beispiel #2
0
 public static void Log(LogHistoryModel model)
 {
     historyList.Add(model);
     if (historyList.Count >= maxListCount)
     {
         SaveHistory();
         historyList.TrimExcess();
     }
 }
Beispiel #3
0
        public override void OnResultExecuting(ResultExecutingContext context)
        {
            base.OnResultExecuting(context);

            var url       = context.HttpContext.Request.Url?.AbsolutePath;
            var urlReffer = context.HttpContext.Request.UrlReferrer?.AbsolutePath;
            var user      = context.HttpContext.User.GetCurrentUserCreads()?.Email;
            var model     = new LogHistoryModel(url, urlReffer, user);

            new Task(() => { LogHistoryService.Log(model); }).Start();
        }
Beispiel #4
0
        public ActionResult Login(LoginModel model)
        {
            try
            {
                //LogHelper.Info("Login model: " + model.LoginID);
                if (string.IsNullOrEmpty(model.LoginID) || string.IsNullOrEmpty(model.Password))
                {
                    ViewBag.ErrorMessage = "Please input all field!!";
                    return(View(model));
                }

                var user = ValidateModel(model);
                if (user != null)
                {
                    //var listUser = new List<string> { "vn55160524", "vn55110755", "vn55104017", "vn55104937", "vd52170016", "vd52170006", "vd52170727", "se201701" };
                    //if (listUser.Contains(model.LoginID.ToLower()))
                    //{
                    var logHistoryRepo = new LoginHistoryRepository();
                    var logHistory     = new LogHistoryModel()
                    {
                        UserId    = model.LoginID,
                        PcBrowser = Request.Browser.Browser,
                        IpAddress = Util.IP2INT(GetIpAddress())
                    };
                    logHistoryRepo.InsertLog(logHistory);

                    var status = AppDictionary.UserStatus.FirstOrDefault(a => a.Value == user.Status.ToString()).Key;
                    if (status == "New" || status == "Reset")
                    {
                        ViewBag.Status = "ChangePassword";
                        return(View(model));
                    }
                    SetAuthorized(user, model.Remember);
                    if (Session["CurUrl"] != null)
                    {
                        return(Redirect(Session["CurUrl"].ToString()));
                    }
                    return(RedirectToAction("Index", "Home"));
                    //}
                    //ViewBag.ErrorMessage = "You dont have permission to login this system";
                }
                ViewBag.ErrorMessage = "Login ID & Password is incorrect!";
            }
            catch (Exception ex)
            {
                LogHelper.Error("AnonymousController: UserId: " + model.LoginID + " Exception: " + ex.InnerException.Message);
                return(null);
            }
            return(View(model));
        }
        public static List <LogHistoryModel> GetLogFiles()
        {
            List <LogHistoryModel> Results = new List <LogHistoryModel>();

            string[] files = Directory.GetFiles(MapPath(Dir), "*.log");
            for (int i = 0; i < files.Length; i++)
            {
                LogHistoryModel ToAdd = new LogHistoryModel();
                ToAdd.id       = i;
                ToAdd.FileName = Path.GetFileName(files[i]);
                Results.Add(ToAdd);
            }
            return(Results);
        }