public bool UpdateAttachment(string emailReference, string attachmentReference, Attachment attachment) { Check.If(emailReference).IsNotNullOrEmpty(); Check.If(attachmentReference).IsNotNullOrEmpty(); Check.If(attachment).IsNotNull(); return _attachmentRepository.UpdateAttachment(emailReference, attachmentReference,attachment); }
public bool CreateAttachment(string emailReference, Attachment attachment) { Check.If(emailReference).IsNotNullOrEmpty(); Check.If(attachment).IsNotNull(); attachment.GenerateReference(_referenceGenerator); return _attachmentRepository.CreateAttachment(emailReference, attachment); }
public bool CreateAttachment(string emailReference, Attachment attachment) { using (var context = new CommunicationsContext(_databaseSettings.ConnectionString)) { var email = context.Emails .Include(e => e.Attachments) .FirstOrDefault(x => x.EmailReference == emailReference); if (email == null) return false; email.Attachments.Add(attachment); return context.SaveChanges() > 0; } }
public bool UpdateAttachment(string emailReference, string attachmentReference, Attachment attachment) { using (var context = new CommunicationsContext(_databaseSettings.ConnectionString)) { var email = context.Emails .Include(e => e.Attachments) .FirstOrDefault(x => x.EmailReference == emailReference); var existingAttachment = email?.Attachments.FirstOrDefault(x => x.AttachmentReference == attachmentReference); if (existingAttachment == null) return false; _attachmentMapper.Map(attachment,existingAttachment); return context.SaveChanges() > 0; } }