public async Task <BadgeCreationDetail> CreateAsync(IFormFile badge) { var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(badge.FileName)}"; var fileDetail = await _filesServices.UploadAsync(badge.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(NewSponsorCommand request, CancellationToken cancellationToken) { var newSponsor = _mapper.Map <Sponsor>(request); if (request.ImageFile != null) { var fileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(request.ImageFile.FileName)}"; var logoUplaod = await filesServices.UploadAsync(request.ImageFile.OpenReadStream(), fileName, Container.Sponsors); if (logoUplaod == null) { return(HttpResponseCodeHelper.NotFound()); } newSponsor.SetFile(logoUplaod.FileUri, logoUplaod.Name); await _context.Sponsors.AddAsync(newSponsor); } await _context.SaveChangesAsync(); var mapped = _mapper.Map <SponsorDetailViewModel>(newSponsor); return(HttpResponseCodeHelper.Ok(mapped)); }
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))); }