Пример #1
0
        private async Task <string> UploadPhotoAsyncInFolder(string userId, IFormFile file)
        {
            var oldImageName = (await _repoWrapper.User.GetFirstOrDefaultAsync(x => x.Id == userId)).ImagePath;

            if (file != null && file.Length > 0)
            {
                using (var img = System.Drawing.Image.FromStream(file.OpenReadStream()))
                {
                    var uploads = Path.Combine(_env.WebRootPath, "images\\Users");
                    if (!string.IsNullOrEmpty(oldImageName) && !string.Equals(oldImageName, "default.png"))
                    {
                        var oldPath = Path.Combine(uploads, oldImageName);
                        if (File.Exists(oldPath))
                        {
                            File.Delete(oldPath);
                        }
                    }
                    var fileName = $"{_uniqueId.GetUniqueId()}{Path.GetExtension(file.FileName)}";
                    var filePath = Path.Combine(uploads, fileName);
                    img.Save(filePath);
                    return(fileName);
                }
            }
            else
            {
                return(oldImageName);
            }
        }
Пример #2
0
        /// <inheritdoc />
        public async Task <CityDocumentsDTO> AddDocumentAsync(CityDocumentsDTO documentDTO)
        {
            var fileBase64 = documentDTO.BlobName.Split(',')[1];
            var extension  = $".{documentDTO.FileName.Split('.').LastOrDefault()}";
            var fileName   = $"{_uniqueId.GetUniqueId()}{extension}";

            await _cityFilesBlobStorage.UploadBlobForBase64Async(fileBase64, fileName);

            documentDTO.BlobName = fileName;

            var documentTypes = await GetAllCityDocumentTypesAsync();

            documentDTO.CityDocumentType = documentTypes
                                           .FirstOrDefault(dt => dt.Name == documentDTO.CityDocumentType.Name);
            documentDTO.CityDocumentTypeId = documentDTO.CityDocumentType.ID;

            var document = _mapper.Map <CityDocumentsDTO, CityDocuments>(documentDTO);

            _repositoryWrapper.CityDocuments.Attach(document);
            await _repositoryWrapper.CityDocuments.CreateAsync(document);

            await _repositoryWrapper.SaveAsync();

            return(documentDTO);
        }
Пример #3
0
        ///<inheritdoc/>
        public async Task <string> GenerateJWTTokenAsync(UserDTO userDTO)
        {
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userDTO.Email),
                new Claim(JwtRegisteredClaimNames.NameId, userDTO.Id),
                new Claim(JwtRegisteredClaimNames.FamilyName, userDTO.Id),
                new Claim(JwtRegisteredClaimNames.Jti, _uniqueId.GetUniqueId().ToString())
            };
            var roles = await _userManagerService.GetRolesAsync(userDTO);

            claims.AddRange(roles.Select(role => new Claim(ClaimsIdentity.DefaultRoleClaimType, role)));
            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtOptions.Key));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(
                issuer: _jwtOptions.Issuer,
                audience: _jwtOptions.Audience,
                claims: claims,
                expires: DateTime.Now.AddMinutes(_jwtOptions.Time),
                signingCredentials: creds);

            var tokenHandler = new JwtSecurityTokenHandler();

            return(tokenHandler.WriteToken(token));
        }
        private async Task UploadPhotoAsync(GoverningBodyDTO governingBody)
        {
            var oldImageName = (await _repoWrapper.GoverningBody.GetFirstOrDefaultAsync(i => i.ID == governingBody.Id))?.Logo;
            var logoBase64   = governingBody.Logo;

            if (!string.IsNullOrWhiteSpace(logoBase64) && logoBase64.Length > 0)
            {
                var logoBase64Parts = logoBase64.Split(',');
                var extension       = logoBase64Parts[0].Split(new[] { '/', ';' }, 3)[1];

                if (!string.IsNullOrEmpty(extension))
                {
                    extension = (extension[0] == '.' ? "" : ".") + extension;
                }

                var fileName = $"{_uniqueId.GetUniqueId()}{extension}";

                await _governingBodyBlobStorage.UploadBlobForBase64Async(logoBase64Parts[1], fileName);

                governingBody.Logo = fileName;
            }

            if (!string.IsNullOrEmpty(oldImageName))
            {
                await _governingBodyBlobStorage.DeleteBlobAsync(oldImageName);
            }
        }
Пример #5
0
        private async Task UploadPhotoAsync(ClubDTO club, IFormFile file)
        {
            var ClubId       = club.ID;
            var oldImageName = (await _repoWrapper.Club.GetFirstOrDefaultAsync(
                                    predicate: i => i.ID == ClubId))
                               ?.Logo;

            club.Logo = GetChangedPhoto("images\\Clubs", file, oldImageName, _env.WebRootPath, _uniqueId.GetUniqueId().ToString());
        }
        public string AddSocket(string userId, WebSocket socket)
        {
            var connectionId = _uniqueId.GetUniqueId().ToString();

            if (!_userMap.UserConnections.ContainsKey(userId))
            {
                _userMap.UserConnections.TryAdd(userId, new HashSet <ConnectionDTO>());
            }
            _userMap.UserConnections[userId].Add(new ConnectionDTO {
                ConnectionId = connectionId, WebSocket = socket
            });
            return(connectionId);
        }
Пример #7
0
        public async Task <int> SaveMethodicDocumentAsync(MethodicDocumentWraperDTO document)
        {
            var repoDoc = _mapper.Map <MethodicDocument>(document.MethodicDocument);

            _repoWrapper.MethodicDocument.Attach(repoDoc);
            _repoWrapper.MethodicDocument.Create(repoDoc);
            if (document.FileAsBase64 != null)
            {
                repoDoc.FileName = $"{_uniqueId.GetUniqueId()}{repoDoc.FileName}";
                await UploadFileToBlobAsync(document.FileAsBase64, repoDoc.FileName);
            }
            await _repoWrapper.SaveAsync();

            return(document.MethodicDocument.ID);
        }
Пример #8
0
        /// <inheritdoc />
        public async Task <int> SaveDecisionAsync(DecisionWrapperDTO decision)
        {
            decision.Decision.DecisionTarget = await CreateDecisionTargetAsync(decision.Decision.DecisionTarget.TargetName);

            var repoDecision = _mapper.Map <Decesion>(decision.Decision);

            _repoWrapper.Decesion.Attach(repoDecision);
            _repoWrapper.Decesion.Create(repoDecision);
            if (decision.FileAsBase64 != null)
            {
                repoDecision.FileName = $"{_uniqueId.GetUniqueId()}{repoDecision.FileName}";
                await UploadFileToBlobAsync(decision.FileAsBase64, repoDecision.FileName);
            }
            await _repoWrapper.SaveAsync();

            return(decision.Decision.ID);
        }
Пример #9
0
        public async Task <RegionDocumentDTO> AddDocumentAsync(RegionDocumentDTO documentDTO)
        {
            var fileBase64 = documentDTO.BlobName.Split(',')[1];
            var extension  = $".{documentDTO.FileName.Split('.').LastOrDefault()}";
            var fileName   = $"{_uniqueId.GetUniqueId()}{extension}";
            await _regionFilesBlobStorageRepository.UploadBlobForBase64Async(fileBase64, fileName);

            documentDTO.BlobName = fileName;

            var document = _mapper.Map <RegionDocumentDTO, RegionDocuments>(documentDTO);

            _repoWrapper.RegionDocument.Attach(document);
            await _repoWrapper.RegionDocument.CreateAsync(document);

            await _repoWrapper.SaveAsync();

            return(documentDTO);
        }
Пример #10
0
        /// <inheritdoc />
        public async Task <IEnumerable <EventGalleryDTO> > AddPicturesAsync(int id, IList <IFormFile> files)
        {
            var uploadedPictures = new List <EventGalleryDTO>();
            var createdGalleries = new List <Gallary>();

            foreach (IFormFile file in files)
            {
                if (file != null && file.Length > 0)
                {
                    var fileName = $"{_uniqueId.GetUniqueId()}{Path.GetExtension(file.FileName)}";
                    await _eventBlobStorage.UploadBlobAsync(file, fileName);

                    var gallery = new Gallary()
                    {
                        GalaryFileName = fileName
                    };
                    await _repoWrapper.Gallary.CreateAsync(gallery);

                    var eventGallery = new EventGallary {
                        EventID = id, Gallary = gallery
                    };
                    await _repoWrapper.EventGallary.CreateAsync(eventGallery);

                    createdGalleries.Add(gallery);
                }
            }
            await _repoWrapper.SaveAsync();

            foreach (var gallery in createdGalleries)
            {
                uploadedPictures.Add(new EventGalleryDTO
                {
                    GalleryId = gallery.ID,
                    FileName  = await _eventBlobStorage.GetBlobBase64Async(gallery.GalaryFileName)
                });
            }

            return(uploadedPictures);
        }