// **************************************
 // URL: /Account/LogOff
 // **************************************
 public void LogOff(int? id)
 {
     try
     {
         var db = new ShowRommSys.Client.Web.Models.ShowRoomSysEntities();
         var user = db.Users.FirstOrDefault(e => e.Id == int.Parse(this.User.Identity.Name));
         user.LastLoginTime = DateTime.Now;
         db.SaveChanges();
     }
     catch { }
     FormsService.SignOut();
 }
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            #region auto generate
            //if (ModelState.IsValid)
            //{
            //    if (MembershipService.ValidateUser(model.UserName, model.Password))
            //    {
            //        FormsService.SignIn(model.UserName, model.RememberMe);
            //        if (Url.IsLocalUrl(returnUrl))
            //        {
            //            return Redirect(returnUrl);
            //        }
            //        else
            //        {
            //            return RedirectToAction("Index", "Home");
            //        }
            //    }
            //    else
            //    {
            //        ModelState.AddModelError("", "The user name or password provided is incorrect.");
            //    }
            //}
            #endregion

            var db = new ShowRommSys.Client.Web.Models.ShowRoomSysEntities();
            var user = db.Users.FirstOrDefault(e => e.Number == model.UserName.Trim() && e.Password == model.Password);
            if (user != null)
            {
                FormsAuthentication.SetAuthCookie(user.Id.ToString(), false);
                db.AddToUserLogSet(new UserLog { UserId = user.Id, LoginTime = DateTime.Now });
                db.SaveChanges();
                return RedirectToAction("main", "site");
            }
            else
            {
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }