public void updatePageHit(String pageName, String userName)
        {
            var pageCount = db.PageHitsEntity.Where(x => x.PageName == pageName && x.Username == userName).Count();

            if (pageCount > 0)
            {
                PageHits pageHitsModel = new PageHits();
                pageHitsModel.PageName = pageName;
                pageHitsModel.Username = userName;

                PageHits updateHit = db.PageHitsEntity.Where(f => f.PageName == pageHitsModel.PageName && f.Username == pageHitsModel.Username).FirstOrDefault();
                updateHit.Hit            += 1;
                updateHit.LastVisitStamp  = hitTimeStamp;
                db.Entry(updateHit).State = EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                PageHits pageHitsModel = new PageHits();
                pageHitsModel.PageName       = pageName;
                pageHitsModel.Username       = userName;
                pageHitsModel.Hit            = 1;
                pageHitsModel.LastVisitStamp = hitTimeStamp;
                db.PageHitsEntity.Add(pageHitsModel);
                db.SaveChanges();
            }
        }
        public ActionResult Login(Users users)
        {
            var userCount = db.UserEntity.Where(x => x.Username == users.Username && x.Password == users.Password).Count();

            if (userCount == 0)
            {
                ViewBag.errorMsg = "Error: Invalid Users or Credentials";
                return(View());
            }
            else
            {
                pageHits.updatePageHit("Account/Login", users.Username);
                Users updateLastLogin = db.UserEntity.Where(x => x.Username == users.Username).FirstOrDefault();
                updateLastLogin.LastLogin       = lastLoginStamp;
                db.Entry(updateLastLogin).State = EntityState.Modified;
                db.SaveChanges();
                FormsAuthentication.SetAuthCookie(users.Username, false);
                return(RedirectToAction("Index", "Home"));
            }
        }
        public void updateSearchHit(String Keyword)
        {
            var query = db.SearchEntity.Where(x => x.Keyword == Keyword).Count();

            if (query > 0)
            {
                //search keyword exists
                Search search = db.SearchEntity.Where(x => x.Keyword == Keyword).FirstOrDefault();
                search.Hit            += 1;
                search.SearchTimeStamp = hitTimeStamp;
                db.Entry(search).State = EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                Search search = new Search();
                search.Keyword         = Keyword;
                search.Hit             = 1;
                search.SearchTimeStamp = hitTimeStamp;
                db.SearchEntity.Add(search);
                db.SaveChanges();
                //search keyword does not exist
            }
        }