public async Task <BadgeCreationDetail> ReplaceAsync(IFormFile newBadge, string oldBadgeName) { var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(newBadge.FileName)}"; await _filesServices.DeleteAsync(oldBadgeName, Container.Badges); var fileDetail = await _filesServices.UploadAsync(newBadge.OpenReadStream(), fileName, Container.Badges); return(new BadgeCreationDetail(fileDetail)); }
public async Task <IActionResult> Handle(UpdateMeCommand request, CancellationToken cancellationToken) { var currentMemberId = currentUser.User.Id; var member = await _context.Members.FirstOrDefaultAsync(x => x.Id == currentMemberId); _mapper.Map(request, member); if (request.ImageFile != null) { var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(request.ImageFile.FileName)}"; var response = await filesServices.UploadAsync(request.ImageFile.OpenReadStream(), fileName, Container.Members); if (!string.IsNullOrEmpty(member.PictureName)) { await filesServices.DeleteAsync(member.PictureName, Container.Members); } member.SetFile(response.FileUri, response.Name); } await _context.SaveChangesAsync(); return(HttpResponseCodeHelper.Ok(_mapper.Map(member, new MemberDetailViewModel()))); }
public async Task <IActionResult> Handle(UpdateSponsorCommand request, CancellationToken cancellationToken) { var sponsor = await _context.Sponsors.FirstOrDefaultAsync(x => x.Id == request.Id); if (sponsor == null) { return(HttpResponseCodeHelper.NotFound()); } _mapper.Map(request, sponsor); if (request.ImageFile != null) { var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(request.ImageFile.FileName)}"; var response = await filesServices.UploadAsync(request.ImageFile.OpenReadStream(), fileName, Container.Sponsors); await filesServices.DeleteAsync(sponsor.LogoFileName, Container.Sponsors); sponsor.SetFile(response.FileUri, response.Name); } await _context.SaveChangesAsync(); return(HttpResponseCodeHelper.Ok(_mapper.Map <Sponsor>(sponsor))); }