nearChepstow
Member
- Joined
- Nov 13, 2020
- Messages
- 6
- Programming Experience
- 1-3
I have 2 images to upload to one table, have got it to the add service and it only adds the one image, so the last attachment insert is overwriting the first one.
Adding 2 images to the table:
var attachment = model.ArticleAttachmentModel.ProcessedFiles.Where(pf => pf.FileByteArray != null).FirstOrDefault();
var attachmentContentFile = model.ArticleContentFileAttachmentModel.ProcessedFiles.Where(pf => pf.FileByteArray != null).FirstOrDefault();
if (attachment != null)
{
if (attachment.FileByteArray.IsImage())
{
var newAttachment = AttachmentService.NewAttachment(db, attachment.FileByteArray, attachment.Extension, FileContext.ArticleImage, false);
newArticleText.Attachment = newAttachment;
//newArticleText.Preview_Image_Attachment_ID = newAttachment.ID;
newArticleText.Preview_Image_Name = attachment.FileName;
}
}
if (attachmentContentFile != null)
{
if (attachmentContentFile.FileByteArray.IsImage())
{
var newContentFileAttachment = AttachmentService.NewAttachment(db, attachmentContentFile.FileByteArray, attachmentContentFile.Extension, FileContext.ArticleContentFile, false);
newArticleText.Attachment = model.ConsistsOfSingleFile ? newContentFileAttachment : null;
//newArticleText.Main_Content_Attachment_ID = newContentFileAttachment.ID;
}
}
db.SaveChanges();
return newArticle;