Ejemplo n.º 1
0
 public bool HasPermission(SessionUserDto sessionUserDto, string[] permissionIds)
 {
     if (permissionIds.Any(n => n == "功能ID"))
     {
         return(true);
     }
     return(sessionUserDto != null && ((string.IsNullOrEmpty(sessionUserDto.EnterpriseID) && sessionUserDto.UserID == "A00001") || sessionUserDto.FunctionIDs.Any(n => permissionIds.Any(m => n.Eq(m)))));
 }
Ejemplo n.º 2
0
 public virtual void Init()
 {
     if (!IsAuthenticated)
     {
         _user = null;
         return;
     }
     ReloadAll(HttpContext.Current.User.Identity.Name);
 }
Ejemplo n.º 3
0
        public async Task <bool> CreateSessionUser(SessionUserDto sessionUserDto)
        {
            //Map to the Data Entity object
            var recDb = Mapper.Map <SessionUser>(sessionUserDto);

            //Insert into Message table
            await _db.InsertAsync(recDb);

            return(recDb.Id > 0);
        }
Ejemplo n.º 4
0
        public async void CreateSessionUser()
        {
            var sessionuser = new SessionUserDto()
            {
                SessionId = 10000,
                UserId    = 3
            };
            var result = await _sessionservice.CreateSessionUser(sessionuser);

            Assert.Equal(true, result);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> AddSessionUser([FromBody, Required] SessionUserDto sessionUserDto)
        {
            try
            {
                if (sessionUserDto == null)
                {
                    return(BadRequest());
                }

                if (await _sessionservice.CreateSessionUser(sessionUserDto))
                {
                    return(CreatedAtRoute("default", true));
                }

                return(BadRequest("Failed to update the database"));
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 6
0
        public ActionResult GetUserLoginStateList(UserLoginStateViewModel model)
        {
            var result = new StandardJsonResult <GridDataModelBase <UserLoginStateDto> >();

            result.Try(() =>
            {
                if (!ModelState.IsValid)
                {
                    throw new KnownException(ModelState.GetFirstError());
                }

                int count    = 0;
                bool showall = false;
                if (HasFunction(Functions.Root_SystemSetting_UserLoginStateManagement_ShowAll))
                {
                    showall = true;
                }

                SessionUserDto _sessionUserDto = new SessionUserDto()
                {
                    DepartmentID = BCSession.User.DepartmentID,
                    EnterpriseID = BCSession.User.EnterpriseID,
                    UserID       = BCSession.User.UserID
                };

                List <UserLoginStateDto> listdto = service.GetUserLoginStateList(_sessionUserDto, showall, model.UserName, model.page, model.rows, out count);
                result.Value = new GridDataModelBase <UserLoginStateDto>()
                {
                    rows  = listdto,
                    total = count
                };
            });
            if (result.Success == false)
            {
                result.Value = new GridDataModelBase <UserLoginStateDto>();
            }
            return(Json(result.Value, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 7
0
        public List <UserLoginStateDto> GetUserLoginStateList(SessionUserDto SNUser, bool ShowAll, string UserName, int pageNumber, int pageSize, out int amount)
        {
            using (var db = new BC.EnterpriseData.Model.BCEnterpriseContext())
            {
                ClearUserLoginState(db);

                string           EnterpriseID = SNUser.EnterpriseID;
                int              DepartmentID = SNUser.DepartmentID == null ? 0 : SNUser.DepartmentID.Value;
                List <FrontUser> FUserList    = new List <FrontUser>();
                List <string>    FUserIds     = new List <string>();
                var              queryfusers  = db.FrontUsers.Where(m => m.EnterpiseID == EnterpriseID);
                if (queryfusers.Count() > 0)
                {
                    FUserList = queryfusers.ToList();//当前企业下的所有用户
                    FUserIds  = FUserList.Select(m => m.UserID).ToList();
                }

                var list = db.UserLoginStates.Where(m => FUserIds.Contains(m.UserID));
                if (!string.IsNullOrEmpty(UserName))
                {
                    list = list.Where(m => m.UserName.Contains(UserName));
                }
                if (ShowAll == false)
                {
                    var        depList   = GetSubDepartmentList(DepartmentID, db);
                    List <int> depIdList = new List <int>();
                    depIdList.Add(DepartmentID);
                    if (depList != null && depList.Count > 0)
                    {
                        depIdList.AddRange(depList.Select(m => m.DepartmentID));//子部门id
                    }

                    var subUsers = FUserList.Where(m => depIdList.Contains(m.DepartmentID.Value));//子部门用户
                    if (subUsers != null && subUsers.Count() > 0)
                    {
                        FUserIds = subUsers.Select(m => m.UserID).ToList();
                        list     = list.Where(m => FUserIds.Contains(m.UserID));
                    }
                    else
                    {
                        amount = 0;
                        return(new List <UserLoginStateDto>());
                    }
                }
                int pagecount;
                amount = list.Count();
                if (pageSize > 0)
                {
                    // 获取总共页数
                    pagecount = (list.Count() + pageSize - 1) / pageSize;
                }
                else
                {
                    pagecount = 0;
                }
                //页码判断,小于1则为1,大于最大页码则为最大页码
                if (pageNumber > pagecount)
                {
                    pageNumber = pagecount;
                }
                if (pageNumber < 1)
                {
                    pageNumber = 1;
                }

                return(list.OrderBy(x => x.UserLoginStateID).Skip(pageSize * (pageNumber - 1)).Take(pageSize).Select(obj => new UserLoginStateDto()
                {
                    UserID = obj.UserID,
                    Device = obj.Device,
                    LoginIP = obj.LoginIP,
                    LoginTime = obj.LoginTime,
                    LoginToken = obj.LoginToken,
                    UserLoginStateID = obj.UserLoginStateID,
                    UserName = obj.UserName
                }).ToList());
            }
        }
Ejemplo n.º 8
0
 public virtual void Logout()
 {
     _user = null;
 }
 public ProjectStatisticsController()
 {
     _user = GetSession().User;
 }