예제 #1
0
 public static List<MenuItem> GetFunctionMenus(int userid)
 {
     using (ShowRoomSysEntities bse = new ShowRoomSysEntities())
     {
         List<MenuItem> results = new List<MenuItem>();
         List<MenuItems> First = bse.MenuItem.Where(p => p.PId == 0 && p.Visible == true).OrderBy(f => f.Index).ToList();
         List<string> list;
         var q = from u in bse.UsersRights
                 join r in bse.Rights on u.RightId equals r.Id
                 where u.UserId == userid
                 select r.Code;
         list = q.ToList();
         var i = from item in bse.MenuItem
                     where item.PId != 0 && item.Visible == true && list.Contains(item.URL)==true
                     orderby item.Index
                     select new MenuItem { icon = item.IconStyle, menuid = item.Id, menuname = item.Name, url = item.URL,pid=item.PId};
         List<MenuItem> items = i.ToList();
         for(int m=0;m<First.Count;m++)
         {
             var sublist = items.Where(e => e.pid == First[m].Id).ToList();
             if (sublist.Count > 0)
             {
                 results.Add(new MenuItem { menuid = First[m].Id, menuname = First[m].Name, menus = sublist });
             }
         }
         return results;
     }
 }
 // **************************************
 // 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);
        }