ChangePresentationInfos - upload delete image and text

This commit is contained in:
PascalMarchesseault
2024-12-31 18:10:11 -05:00
parent 7ac5b7315b
commit 6b0cc416a9
2 changed files with 54 additions and 33 deletions

View File

@@ -52,14 +52,14 @@ public class PresentationInfos
[MaxLength(255)] public string PhoneNumber { get; set; } = string.Empty; [MaxLength(255)] public string PhoneNumber { get; set; } = string.Empty;
[MaxLength(255)] public string Email { get; set; } = string.Empty; [MaxLength(255)] public string Email { get; set; } = string.Empty;
[MaxLength(2000)] public string Title { get; set; } = string.Empty; [MaxLength(2000)] public string Title { get; set; } = string.Empty;
[MaxLength(2000)] public string MainImageUrl { get; set; } = string.Empty; [MaxLength(2000)] public string? MainImageUrl { get; set; } = string.Empty;
[MaxLength(10000)] public string MainImageText { get; set; } = string.Empty; [MaxLength(10000)] public string MainImageText { get; set; } = string.Empty;
[MaxLength(10000)] public string MainVideoText { get; set; } = string.Empty; [MaxLength(10000)] public string MainVideoText { get; set; } = string.Empty;
[MaxLength(2000)] public string ImagesSubtitle { get; set; } = string.Empty; [MaxLength(2000)] public string ImagesSubtitle { get; set; } = string.Empty;
[MaxLength(2000)] public string Image1Url { get; set; } = string.Empty; [MaxLength(2000)] public string? Image1Url { get; set; } = string.Empty;
[MaxLength(2000)] public string Image2Url { get; set; } = string.Empty; [MaxLength(2000)] public string? Image2Url { get; set; } = string.Empty;
[MaxLength(2000)] public string Image3Url { get; set; } = string.Empty; [MaxLength(2000)] public string? Image3Url { get; set; } = string.Empty;
[MaxLength(2000)] public string Image4Url { get; set; } = string.Empty; [MaxLength(2000)] public string? Image4Url { get; set; } = string.Empty;
[MaxLength(10000)] public string ImagesText { get; set; } = string.Empty; [MaxLength(10000)] public string ImagesText { get; set; } = string.Empty;
[MaxLength(2000)] public string VideoSubtitle { get; set; } = string.Empty; [MaxLength(2000)] public string VideoSubtitle { get; set; } = string.Empty;
[MaxLength(2000)] public string VideoSubtitleMain { get; set; } = string.Empty; [MaxLength(2000)] public string VideoSubtitleMain { get; set; } = string.Empty;

View File

@@ -18,6 +18,11 @@ public record ChangePresentationInfosRequest(
string? VideoUrlMain, string? VideoUrlMain,
string? VideoUrl, string? VideoUrl,
string? VideoText, string? VideoText,
string? MainImageUrl,
string? Image1Url,
string? Image2Url,
string? Image3Url,
string? Image4Url,
IFormFile? MainImage, IFormFile? MainImage,
IFormFile? Image1, IFormFile? Image1,
IFormFile? Image2, IFormFile? Image2,
@@ -54,39 +59,55 @@ public class ChangePresentationInfosHandler(
return; return;
} }
// Upload images if provided and update URLs async Task<string> UploadFileOrDefaultAsync(
async Task<string?> UploadFileAsync(IFormFile? file, string subDirectory, string fileName) IFormFile? file,
string subDirectory,
string fileName,
string? newUrl)
{ {
if (file is null) if (newUrl == "")
return null; return "";
return await blobStorage.UploadFileAsync( if (file != null)
ContainerNames.Creators, {
$"{request.CreatorId}/{subDirectory}/{fileName}", return await blobStorage.UploadFileAsync(
file.OpenReadStream(), ContainerNames.Creators,
file.ContentType, $"{request.CreatorId}/{subDirectory}/{fileName}",
ct); file.OpenReadStream(),
file.ContentType,
ct);
}
return newUrl?.Trim() ?? "";
} }
creator.PresentationInfos.MainImageUrl = await UploadFileAsync(request.MainImage, "Profile", "MainImage") ?? creator.PresentationInfos.MainImageUrl; creator.PresentationInfos.MainImageUrl = await UploadFileOrDefaultAsync(
creator.PresentationInfos.Image1Url = await UploadFileAsync(request.Image1, "Profile", "Image1") ?? creator.PresentationInfos.Image1Url; request.MainImage, "Profile", "MainImage", request.MainImageUrl);
creator.PresentationInfos.Image2Url = await UploadFileAsync(request.Image2, "Profile", "Image2") ?? creator.PresentationInfos.Image2Url;
creator.PresentationInfos.Image3Url = await UploadFileAsync(request.Image3, "Profile", "Image3") ?? creator.PresentationInfos.Image3Url;
creator.PresentationInfos.Image4Url = await UploadFileAsync(request.Image4, "Profile", "Image4") ?? creator.PresentationInfos.Image4Url;
// Update other fields creator.PresentationInfos.Image1Url = await UploadFileOrDefaultAsync(
creator.PresentationInfos.PhoneNumber = request.PhoneNumber ?? creator.PresentationInfos.PhoneNumber; request.Image1, "Profile", "Image1", request.Image1Url);
creator.PresentationInfos.Email = request.Email ?? creator.PresentationInfos.Email;
creator.PresentationInfos.Title = request.Title ?? creator.PresentationInfos.Title; creator.PresentationInfos.Image2Url = await UploadFileOrDefaultAsync(
creator.PresentationInfos.MainImageText = request.MainImageText ?? creator.PresentationInfos.MainImageText; request.Image2, "Profile", "Image2", request.Image2Url);
creator.PresentationInfos.MainVideoText = request.MainVideoText ?? creator.PresentationInfos.MainVideoText;
creator.PresentationInfos.ImagesSubtitle = request.ImagesSubtitle ?? creator.PresentationInfos.ImagesSubtitle; creator.PresentationInfos.Image3Url = await UploadFileOrDefaultAsync(
creator.PresentationInfos.ImagesText = request.ImagesText ?? creator.PresentationInfos.ImagesText; request.Image3, "Profile", "Image3", request.Image3Url);
creator.PresentationInfos.VideoSubtitle = request.VideoSubtitle ?? creator.PresentationInfos.VideoSubtitle;
creator.PresentationInfos.VideoSubtitleMain = request.VideoSubtitleMain ?? creator.PresentationInfos.VideoSubtitleMain; creator.PresentationInfos.Image4Url = await UploadFileOrDefaultAsync(
creator.PresentationInfos.VideoUrlMain = request.VideoUrlMain ?? creator.PresentationInfos.VideoUrlMain; request.Image4, "Profile", "Image4", request.Image4Url);
creator.PresentationInfos.VideoUrl = request.VideoUrl ?? creator.PresentationInfos.VideoUrl;
creator.PresentationInfos.VideoText = request.VideoText ?? creator.PresentationInfos.VideoText; creator.PresentationInfos.PhoneNumber = request.PhoneNumber?.Trim() ?? "";
creator.PresentationInfos.Email = request.Email?.Trim() ?? "";
creator.PresentationInfos.Title = request.Title?.Trim() ?? "";
creator.PresentationInfos.MainImageText = request.MainImageText?.Trim() ?? "";
creator.PresentationInfos.MainVideoText = request.MainVideoText?.Trim() ?? "";
creator.PresentationInfos.ImagesSubtitle = request.ImagesSubtitle?.Trim() ?? "";
creator.PresentationInfos.ImagesText = request.ImagesText?.Trim() ?? "";
creator.PresentationInfos.VideoSubtitle = request.VideoSubtitle?.Trim() ?? "";
creator.PresentationInfos.VideoSubtitleMain = request.VideoSubtitleMain?.Trim() ?? "";
creator.PresentationInfos.VideoUrlMain = request.VideoUrlMain?.Trim() ?? "";
creator.PresentationInfos.VideoUrl = request.VideoUrl?.Trim() ?? "";
creator.PresentationInfos.VideoText = request.VideoText?.Trim() ?? "";
await context.SaveChangesAsync(ct); await context.SaveChangesAsync(ct);
await SendOkAsync(ct); await SendOkAsync(ct);