예제 #1
0
        public CrResult <ChannelRoleDto> CreateChannel(ChannelCrDto channelDto, long userId)
        {
            var result = new CrResult <ChannelRoleDto>();

            CheckData(result, channelDto);
            if (result.ActionResult == ActionResult.Success)
            {
                try
                {
                    var c        = _context.Channel.Add(Converter.ConvertToChannel(channelDto));
                    var userRole = UserRolesManager.AddUserRole(c.channel_id, userId, _adminId, _context);
                    _context.SaveChanges();
                    userRole.Role = new Role
                    {
                        role_id   = 0,
                        role_name = "Admin"
                    };
                    result.CreatedObject = Converter.ConvertToChannelRoleDto(userRole);
                }
                catch (DbUpdateException)
                {
                    result.ActionResult = ActionResult.DatabaseError;
                }
            }
            return(result);
        }
예제 #2
0
        public DbRequestResult <List <UserDto> > GetChannelsUsers(long userId, long channelId)
        {
            var res             = new DbRequestResult <List <UserDto> >();
            var isActionAllowed = new UserRolesManager().CheckPermition(userId, channelId, _watchMemberPermitionId);

            if (isActionAllowed)
            {
                var channelRoles = _context.UserRole.Where(uRole => uRole.channel_id == channelId).
                                   Select(c => Converter.ConvertToUserDto(c.User)).ToList();
                res.CreatedObject = channelRoles;
            }
            else
            {
                res.ActionResult = ActionResult.PermissionDenied;
            }
            return(res);
        }