ChangePresentationInfos - upload delete image and text
This commit is contained in:
@@ -52,14 +52,14 @@ public class PresentationInfos
|
||||
[MaxLength(255)] public string PhoneNumber { 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 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 MainVideoText { 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 Image2Url { 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? Image1Url { 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? Image4Url { 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 VideoSubtitleMain { get; set; } = string.Empty;
|
||||
|
||||
@@ -18,6 +18,11 @@ public record ChangePresentationInfosRequest(
|
||||
string? VideoUrlMain,
|
||||
string? VideoUrl,
|
||||
string? VideoText,
|
||||
string? MainImageUrl,
|
||||
string? Image1Url,
|
||||
string? Image2Url,
|
||||
string? Image3Url,
|
||||
string? Image4Url,
|
||||
IFormFile? MainImage,
|
||||
IFormFile? Image1,
|
||||
IFormFile? Image2,
|
||||
@@ -54,39 +59,55 @@ public class ChangePresentationInfosHandler(
|
||||
return;
|
||||
}
|
||||
|
||||
// Upload images if provided and update URLs
|
||||
async Task<string?> UploadFileAsync(IFormFile? file, string subDirectory, string fileName)
|
||||
async Task<string> UploadFileOrDefaultAsync(
|
||||
IFormFile? file,
|
||||
string subDirectory,
|
||||
string fileName,
|
||||
string? newUrl)
|
||||
{
|
||||
if (file is null)
|
||||
return null;
|
||||
if (newUrl == "")
|
||||
return "";
|
||||
|
||||
return await blobStorage.UploadFileAsync(
|
||||
ContainerNames.Creators,
|
||||
$"{request.CreatorId}/{subDirectory}/{fileName}",
|
||||
file.OpenReadStream(),
|
||||
file.ContentType,
|
||||
ct);
|
||||
if (file != null)
|
||||
{
|
||||
return await blobStorage.UploadFileAsync(
|
||||
ContainerNames.Creators,
|
||||
$"{request.CreatorId}/{subDirectory}/{fileName}",
|
||||
file.OpenReadStream(),
|
||||
file.ContentType,
|
||||
ct);
|
||||
}
|
||||
|
||||
return newUrl?.Trim() ?? "";
|
||||
}
|
||||
|
||||
creator.PresentationInfos.MainImageUrl = await UploadFileAsync(request.MainImage, "Profile", "MainImage") ?? creator.PresentationInfos.MainImageUrl;
|
||||
creator.PresentationInfos.Image1Url = await UploadFileAsync(request.Image1, "Profile", "Image1") ?? creator.PresentationInfos.Image1Url;
|
||||
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;
|
||||
creator.PresentationInfos.MainImageUrl = await UploadFileOrDefaultAsync(
|
||||
request.MainImage, "Profile", "MainImage", request.MainImageUrl);
|
||||
|
||||
// Update other fields
|
||||
creator.PresentationInfos.PhoneNumber = request.PhoneNumber ?? creator.PresentationInfos.PhoneNumber;
|
||||
creator.PresentationInfos.Email = request.Email ?? creator.PresentationInfos.Email;
|
||||
creator.PresentationInfos.Title = request.Title ?? creator.PresentationInfos.Title;
|
||||
creator.PresentationInfos.MainImageText = request.MainImageText ?? creator.PresentationInfos.MainImageText;
|
||||
creator.PresentationInfos.MainVideoText = request.MainVideoText ?? creator.PresentationInfos.MainVideoText;
|
||||
creator.PresentationInfos.ImagesSubtitle = request.ImagesSubtitle ?? creator.PresentationInfos.ImagesSubtitle;
|
||||
creator.PresentationInfos.ImagesText = request.ImagesText ?? creator.PresentationInfos.ImagesText;
|
||||
creator.PresentationInfos.VideoSubtitle = request.VideoSubtitle ?? creator.PresentationInfos.VideoSubtitle;
|
||||
creator.PresentationInfos.VideoSubtitleMain = request.VideoSubtitleMain ?? creator.PresentationInfos.VideoSubtitleMain;
|
||||
creator.PresentationInfos.VideoUrlMain = request.VideoUrlMain ?? creator.PresentationInfos.VideoUrlMain;
|
||||
creator.PresentationInfos.VideoUrl = request.VideoUrl ?? creator.PresentationInfos.VideoUrl;
|
||||
creator.PresentationInfos.VideoText = request.VideoText ?? creator.PresentationInfos.VideoText;
|
||||
creator.PresentationInfos.Image1Url = await UploadFileOrDefaultAsync(
|
||||
request.Image1, "Profile", "Image1", request.Image1Url);
|
||||
|
||||
creator.PresentationInfos.Image2Url = await UploadFileOrDefaultAsync(
|
||||
request.Image2, "Profile", "Image2", request.Image2Url);
|
||||
|
||||
creator.PresentationInfos.Image3Url = await UploadFileOrDefaultAsync(
|
||||
request.Image3, "Profile", "Image3", request.Image3Url);
|
||||
|
||||
creator.PresentationInfos.Image4Url = await UploadFileOrDefaultAsync(
|
||||
request.Image4, "Profile", "Image4", request.Image4Url);
|
||||
|
||||
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 SendOkAsync(ct);
|
||||
|
||||
Reference in New Issue
Block a user