private async Task <ICollection <SendedAtachment> > ConvertFormFilesToSendedAttachments(ICollection <IFormFile> attachments) { if (attachments == null || attachments.Count == 0) { return(null); } HashSet <SendedAtachment> sendedAtachments = new HashSet <SendedAtachment> (); foreach (var attachment in attachments) { if (attachment.Length > 0) { using (var ms = new MemoryStream()) { await attachment.CopyToAsync(ms); var attachmentBytes = ms.ToArray(); var name = attachment.Name; if (name == null) { name = attachment.FileName; } var sendedAttachment = new SendedAtachment(name, attachment.ContentType, attachmentBytes); sendedAtachments.Add(sendedAttachment); } } } return(await Task.FromResult(sendedAtachments)); }
public async Task CreateAsync(string name, string contentType, byte[] data) { var sendedAtachment = new SendedAtachment(name, contentType, data); await _sendedAtachmentRepository.AddAsync(sendedAtachment); }
public async Task UpdateAsync(SendedAtachment sendedAtachment) { _context.SendedAtachments.Update(sendedAtachment); await _context.SaveChangesAsync(); }
public async Task DeleteAsync(SendedAtachment sendedAtachment) { _context.SendedAtachments.Remove(sendedAtachment); await _context.SaveChangesAsync(); }
public async Task AddAsync(SendedAtachment sendedAtachment) { await _context.AddAsync(sendedAtachment); await _context.SaveChangesAsync(); }