Пример #1
0
        public async Task AddFromSportAndSchoolAsync(AddFromSportAndSchoolViewModel model)
        {
            var school = await _repo.Schools.GetByIdAsync(model.SchoolId);

            if (school == null)
            {
                return;
            }
            var stream = await new AzureStorage(school.ProfileContainer, true).DownloadToStreamAsync(school.ProfileBlob);

            foreach (var sportId in model.SportIds)
            {
                stream.Position = 0;
                var storageItem = await new AzureStorage("teamprofiles").UploadToAzureAsync(stream, $"file_{Guid.NewGuid().ToString()}{Path.GetExtension(school.ProfileBlob)}", MemoryFile.GetContentType(school.ProfileBlob), school.ProfileBlob);
                await AddAsync(new TeamViewModel()
                {
                    SchoolId         = model.SchoolId,
                    IsActive         = true,
                    Nickname         = school.Nickname,
                    FacebookUrl      = school.FacebookUrl,
                    TwitterUrl       = school.TwitterUrl,
                    InstagramUrl     = school.InstagramUrl,
                    PrimaryColor     = school.PrimaryColor,
                    SecondaryColor   = school.SecondaryColor,
                    SportId          = sportId,
                    WebsiteUrl       = school.WebsiteUrl,
                    ProfileBlob      = storageItem.Blob,
                    ProfileContainer = storageItem.Container,
                    ProfilePublicUrl = storageItem.Url,
                });
            }
        }