Exemplo n.º 1
0
        public static List <UserPermissionDTO> BuildTreeAndReturnRootNodes(List <UserPermission> AllPermission, List <UserPermission> AssignedPermission)
        {
            List <UserPermissionDTO> MenuList = new List <UserPermissionDTO>();
            var byIdLookup = AllPermission.ToLookup(p => new { p.MenuId, p.MenuName, p.IconName });

            foreach (var item in byIdLookup)
            {
                UserPermissionDTO menus = new UserPermissionDTO();
                menus.MenuId   = item.Key.MenuId;
                menus.MenuName = item.Key.MenuName;
                menus.IconName = item.Key.IconName;

                foreach (var inneritem in AllPermission)
                {
                    if (inneritem.MenuId == menus.MenuId)
                    {
                        foreach (var p in AssignedPermission)
                        {
                            if (p.SubMenuId == inneritem.SubMenuId)
                            {
                                inneritem.isChecked = true;
                                menus.IsChecked     = true;
                            }
                        }
                        menus.Children.Add(inneritem);
                    }
                }
                MenuList.Add(menus);
            }
            return(MenuList);
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> GetById(int id)
        {
            UserPermissionDTO UserPermission = await UserPermissionService.GetAll().Where(x => x.Id == id && !x.Deleted).ProjectTo <UserPermissionDTO>().FirstOrDefaultAsync();

            if (UserPermission == null)
            {
                return(NotFound());
            }
            return(Ok(UserPermission));
        }
Exemplo n.º 3
0
        public static UserPermissionDTO Map(this UserPermission source)
        {
            var target = new UserPermissionDTO();

            target.Id             = source.Id;
            target.IdPermission   = source.IdPermission;
            target.IdUser         = source.IdUser;
            target.LastModifyDate = source.LastModifyDate;

            return(target);
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> Create([FromBody] UserPermissionDTO UserPermissionDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var entity = UserPermissionDto.ToEntity();

            entity.CreateUserId = User.Identity.GetUserId();
            entity.CreateTime   = DateTime.Now;
            await UserPermissionService.InsertAsync(entity);

            return(Ok(entity.ToModel()));
        }
        public IActionResult AssignPermission([FromBody] UserPermissionDTO PermissionIds)
        {
            var response = _permissionService.AssignPermission(PermissionIds, Context);

            return(ServiceResponse(response));
            //switch (response.Status)
            //{
            //    case BusinessStatus.InputValidationFailed:
            //        return Ok(response);
            //    case BusinessStatus.Created:
            //        return Ok(response);
            //    case BusinessStatus.UnAuthorized:
            //        return Unauthorized();
            //    default:
            //        return Forbid();
            //}
        }
        public void TestUserPermissions()
        {
            using (Hobby.SimpleInjector.SimpleInjectorConsole.Instance.BeginLifetimeScope())
            {
                var uow = IoCCProvider.Container.GetInstance <IUnitOfWork>();

                var categorie = new CategoryDTO
                {
                    Name = "testCategorie1"
                };

                var permissions = new PermissionDTO
                {
                    Name        = "testPermission1",
                    Deleted     = false,
                    Description = "TEST"
                };

                var user = new UserDTO
                {
                    FirstName = "testlogin1",
                    Password  = "******"
                };
                //Trzeba przypsiac do obiektu
                var entityPer = permissions.Map();
                var entityUse = user.Map();

                uow.Permissions.Add(entityPer);
                uow.Users.Add(entityUse);
                uow.Save();

                var userPermission = new UserPermissionDTO()
                {
                    IdPermission = entityPer.Id,
                    IdUser       = entityUse.Id
                };
                uow.UserPermissions.Add(userPermission.Map());
                uow.Save();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Assigns the permission.
        /// </summary>
        /// <param name="permissionIds">The permission ids.</param>
        /// <param name="apiContext">The API context.</param>
        /// <returns></returns>
        public UserPermissionResponse AssignPermission(UserPermissionDTO permissionIds, ApiContext apiContext)
        {
            _context = (AVOUMContext)DbManager.GetContext(apiContext.ProductType, apiContext.ServerType);
            UserPermissionsDTO userPermissions = null;

            for (int i = 0; i < permissionIds.PermissionIds.Length; i++)
            {
                userPermissions              = new UserPermissionsDTO();
                userPermissions.UserId       = permissionIds.UserId;
                userPermissions.PermissionId = Convert.ToInt16(permissionIds.PermissionIds[i]);
                userPermissions.UserorRole   = "User";
                // userPermissions.CreatedBy = CreatedBy;
                userPermissions.CreatedDate = DateTime.Now;
                userPermissions.Status      = true;
                var _usersPer = _mapper.Map <TblUserPermissions>(userPermissions);
                _context.TblUserPermissions.Add(_usersPer);
            }
            _context.SaveChanges();
            //return userPermissions;
            return(new UserPermissionResponse {
                Status = BusinessStatus.Created, perm = userPermissions, ResponseMessage = $"Assigned {userPermissions.PermissionId} Permissions successfully!!"
            });
        }
Exemplo n.º 8
0
 public List <UserPermissionDTO> GetUserPermissionList(string UserId, string process)
 {
     try
     {
         //if (checkHavePermission(UserId, "ADMIN", "Role Permission"))
         //{
         List <UserPermissionDTO> list = new List <UserPermissionDTO>();
         SqlParameter[]           sqlp =
         {
             new SqlParameter("Process", DBNull.Value)
         };
         if (!string.IsNullOrEmpty(process))
         {
             sqlp[0].Value = process;
         }
         var perList = Db.Database.SqlQuery <UserPermissionSP>("exec [K2_GetRolePermissionList] @Process", sqlp).ToList();
         foreach (var p in perList)
         {
             UserPermissionDTO tmp = new UserPermissionDTO();
             tmp.RolePermissionGUID = p.RolePermissionGUID.Split(',');
             tmp.Permission         = p.Permission;
             tmp.Role    = p.Role;
             tmp.Process = p.Process;
             list.Add(tmp);
         }
         return(list);
         //}
         //else
         //{
         //    throw new UnauthorizedAccessException();
         //}
     } catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 9
0
        public List <UserPermissionDTO> FindByObjList(object data)
        {
            List <SqlParameter> parameterList = new List <SqlParameter>();

            objList   = new List <UserPermissionDTO>();
            dataTable = null;

            string procName = "sp_M_USER_PERMISSION_FindByColumn";

            try
            {
                dataTable = new DataTable();
                adapter   = new SqlDataAdapter();
                SqlConnection conn = OpenConnection();
                if (data != null)
                {
                    parameterList.AddRange(GetParameters(procName, data).ToArray());
                }
                command             = new SqlCommand(procName, conn);
                command.CommandType = CommandType.StoredProcedure;
                if (data != null)
                {
                    command.Parameters.AddRange(parameterList.ToArray());
                }



                using (SqlDataReader reader = command.ExecuteReader())
                {
                    // objList = DTO.Util.ConvertX.GetListFromDataReader<MenuDTO>(reader) as List<MenuDTO>;
                    while (reader.Read())
                    {
                        obj = new UserPermissionDTO();
                        obj.USER_PERMISSION_OID = reader["USER_PERMISSION_OID"].ToString();
                        obj.MENU_OID            = reader["MENU_OID"].ToString();
                        obj.UserID       = reader["UserID"].ToString();
                        obj.UserLogin    = reader["UserLogin"].ToString();
                        obj.Password     = reader["Password"].ToString();
                        obj.Title        = reader["Title"].ToString();
                        obj.NickName     = reader["NickName"].ToString();
                        obj.FirstName    = reader["FirstName"].ToString();
                        obj.LastName     = reader["LastName"].ToString();
                        obj.UserType     = reader["UserType"].ToString();
                        obj.UserTypeName = reader["UserTypeName"].ToString();
                        obj.UserRegion   = reader["UserRegion"].ToString();
                        obj.UserPlan     = reader["UserPlan"].ToString();
                        obj.Department   = reader["Department"].ToString();
                        obj.Position     = reader["Position"].ToString();
                        obj.Company      = reader["Company"].ToString();
                        obj.PositionPSI  = reader["PositionPSI"].ToString();
                        obj.VIEW         = reader["VIEW"].ToString();
                        obj.EDIT         = reader["EDIT"].ToString();
                        obj.DELETE       = reader["DELETE"].ToString();
                        obj.APPROVE      = reader["APPROVE"].ToString();
                        obj.ROW_STATE    = reader["ROW_STATE"].ToString();
                        obj.Screen       = reader["Screen"].ToString();
                        objList.Add(obj);
                        // ReadSingleRow((IDataRecord)reader);
                    }
                }
            }
            catch (Exception ex) { }
            finally
            {
                CloseConnection();
            }
            return(objList);
        }
Exemplo n.º 10
0
 public static UserPermission ToEntity(this UserPermissionDTO dto, UserPermission entity)
 {
     return(Mapper.Map(dto, entity));
 }
Exemplo n.º 11
0
 public static UserPermission ToEntity(this UserPermissionDTO dto)
 {
     return(Mapper.Map <UserPermissionDTO, UserPermission>(dto));
 }
Exemplo n.º 12
0
 public UserPermissionResponse AssignPermission(UserPermissionDTO permissionIds, ApiContext apiContext)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
 public UserPermissionResponse AssignPermission(UserPermissionDTO permissionIds, ApiContext apiContext)
 {
     return(_permissionService(apiContext.ProductType).AssignPermission(permissionIds, apiContext));
 }