Example #1
0
        /// <inheritdoc/>
        public string Generate(string firstName, string fileExt)
        {
            var isUniqueId = false;
            var counter    = 1;

            do
            {
                var avatarId   = $"{firstName}_{counter}";
                var avatarPath = Path.ChangeExtension(
                    avatarPathProvider.MapPath(avatarId),
                    fileExt);

                isUniqueId = !(Directory.GetFiles(
                                   Path.GetDirectoryName(avatarPath),
                                   Path.ChangeExtension(avatarId, "*")).Any());
                if (isUniqueId)
                {
                    return(Path.ChangeExtension(avatarId, fileExt));
                }

                counter++;
            } while (true);
        }
Example #2
0
        /// <inheritdoc/>
        public async Task <byte[]> GetAvatarBytesAsync(string avatarId)
        {
            var avatarPath = avatarPathProvider.MapPath(avatarId);

            return(await File.ReadAllBytesAsync(avatarPath));
        }