示例#1
0
        public IQueryable <UserBriefDto> GetBriefAll()
        {
            List <UserBriefDto> dtos = new List <UserBriefDto>();

            using (_context)
            {
                IRepository <User> userRep = _context.GetRepository <User>();
                IRepository <Role> roleRep = _context.GetRepository <Role>();

                IQueryable <User> users = userRep.FindAll();
                IQueryable <Role> roles = roleRep.FindAll();

                foreach (var user in users)
                {
                    UserBriefDto dto  = Mapper.Map <User, UserBriefDto>(user);
                    Role         role = roles.FirstOrDefault(r => r.Id.Equals(user.RoleId));
                    if (role != null)
                    {
                        dto.Rolename = role.Rolename;
                    }

                    dtos.Add(dto);
                }
            }

            return(dtos.AsQueryable());
        }
示例#2
0
        public ActionResult Login(UserViewModel uvm)
        {
            LoginUserValidator validator = new LoginUserValidator();
            ValidationResult   result    = validator.Validate(uvm.LoginUserDto);

            if (!result.IsValid)
            {
                result.Errors.ToList().ForEach(error =>
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                });
            }
            else
            {
                UserBriefDto dto = uvm.FindUserByNameAndPwd(uvm.LoginUserDto.Username, uvm.LoginUserDto.Userpwd);
                if (dto == null)
                {
                    return(View());
                }

                Response.Cookies.Add(CookieService.SaveCookies(dto.Id.ToString()));
                return(Redirect("~/APManage/Default/Index"));
            }

            return(View());
        }
示例#3
0
        private void GetBasicInfo()
        {
            UserBriefDto dto = GetCurrentUser();

            ViewBag.LoginUser = dto.Username;
            ViewBag.LoginRole = dto.Rolename;
            //ViewBag.DefaultDate = DateTime.Now.ToString("yyyy-MM-dd");
        }
示例#4
0
        public ActionResult Index()
        {
            UserBriefDto dto = GetCurrentUser();

            ViewBag.LoginUser = dto.Username;
            ViewBag.LoginRole = dto.Rolename;
            return(View(model));
        }
示例#5
0
        public UserBriefDto FindUserByNameAndPwd(string name, string pwd)
        {
            UserBriefDto dto = _us.GetLoginUserByName(name);

            if (dto != null)
            {
                if (dto.Username.Trim().ToLower().Equals(name) &&
                    dto.Userpwd.Equals(EncryptUtils.MD5Encrypt(pwd)))
                {
                    return(dto);
                }
            }

            return(null);
        }
示例#6
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpCookie cookie = Request.Cookies["AP_Guid"];

            List <string> ActionNameList = new List <string>();

            ActionNameList.Add("Login");

            UserBriefDto dto = GetLoginUser(cookie);

            if ((dto == null || string.IsNullOrEmpty(dto.Username)) &&
                !ActionNameList.Contains(filterContext.ActionDescriptor.ActionName))
            {
                filterContext.Result = RedirectToAction("Login", "Default");
            }

            base.OnActionExecuting(filterContext);
        }
示例#7
0
        public UserBriefDto GetLoginUserById(string uid)
        {
            using (_context)
            {
                IRepository <User> userRep = _context.GetRepository <User>();
                IRepository <Role> roleRep = _context.GetRepository <Role>();

                User user = ((IUserRepository)userRep).FindBy(new Guid(uid));
                Role role = ((IRoleRepository)roleRep).FindBy(user.RoleId);

                if (user != null && role != null)
                {
                    UserBriefDto dto = Mapper.Map <User, UserBriefDto>(user);
                    dto.Rolename = role.Rolename;
                    return(dto);
                }
            }

            return(null);
        }