public async Task <Attachment> GetAsync(AttachmentEndpointType type, Guid parent, Guid attachmentId) { IEnumerable <Attachment> attachmentList = await Client.GetAsync <Attachment, AttachmentsResponse>($"{_endpointBase}/{type}/{parent:D}/Attachments").ConfigureAwait(false); if (attachmentList.Count() == 0 || attachmentList.FirstOrDefault(a => a.Id == attachmentId) == null) { throw new NotFoundException(); } string fileName = attachmentList.First(a => a.Id == attachmentId).FileName; var response = await Client.GetAsync($"{_endpointBase}/{type}/{parent:D}/Attachments/{attachmentId.ToString()}").ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.OK) { var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); Attachment attachment = new Attachment(stream, fileName, response.Content.Headers.ContentType.ToString(), (int)stream.Length) { Id = attachmentId }; return(attachment); } await Client.HandleErrorsAsync(response).ConfigureAwait(false); return(null); }
public Attachment AddOrReplace(Attachment attachment, AttachmentEndpointType type, Guid parent) { var mimeType = MimeTypes.GetMimeType(attachment.FileName); return Client.Post<Attachment, AttachmentsResponse>(string.Format("/api.xro/2.0/{0}/{1}/Attachments/{2}", type, parent.ToString("D"), attachment.FileName), attachment.Content, mimeType).FirstOrDefault(); }
public virtual Attachment Get(AttachmentEndpointType type, Guid parent, string fileName) { var mimeType = MimeTypes.GetMimeType(fileName); var data = Client.Get(string.Format("/api.xro/2.0/{0}/{1}/Attachments/{2}", type, parent.ToString("D"), fileName), mimeType); if (data.StatusCode == HttpStatusCode.OK) { return(new Attachment(data.Stream, fileName, data.ContentType, data.ContentLength)); } Client.HandleErrors(data); return(null); }
public Attachment AddOrReplace(Attachment attachment, AttachmentEndpointType type, Guid parent, bool includeOnline = false) { var mimeType = MimeTypes.GetMimeType(attachment.FileName); var url = string.Format("/api.xro/2.0/{0}/{1}/Attachments/{2}", type, parent.ToString("D"), attachment.FileName); if (SupportsOnline(type) && includeOnline) { Client.Parameters.Add("IncludeOnline", true); } return(Client.Post <Attachment, AttachmentsResponse>(url, attachment.Content, mimeType).FirstOrDefault()); }
public Attachment AddOrReplace(Attachment attachment, AttachmentEndpointType type, Guid parent, bool includeOnline = false) { var mimeType = MimeTypes.GetMimeType(attachment.FileName); var url = string.Format("/api.xro/2.0/{0}/{1}/Attachments/{2}", type, parent.ToString("D"), attachment.FileName); if (SupportsOnline(type) && includeOnline) { Client.Parameters.Add("IncludeOnline", true); } return Client.Post<Attachment, AttachmentsResponse>(url, attachment.Content, mimeType).FirstOrDefault(); }
public Attachment Get(AttachmentEndpointType type, Guid parent, string fileName) { var mimeType = MimeTypes.GetMimeType(fileName); var data = Client.Get(string.Format("/api.xro/2.0/{0}/{1}/Attachments/{2}", type, parent.ToString("D"), fileName), mimeType); if (data.StatusCode == HttpStatusCode.OK) { return new Attachment(data.Stream, fileName, data.ContentType, data.ContentLength); } Client.HandleErrors(data); return null; }
public async Task <Attachment> GetAsync(AttachmentEndpointType type, Guid parent, string fileName) { var response = await Client.GetAsync(string.Format("/api.xro/2.0/{0}/{1}/Attachments/{2}", type, parent.ToString("D"), fileName)); if (response.StatusCode == HttpStatusCode.OK) { var stream = await response.Content.ReadAsStreamAsync(); return(new Attachment(stream, fileName, response.Content.Headers.ContentType.ToString(), (int)stream.Length)); } await Client.HandleErrorsAsync(response); return(null); }
public async Task <Attachment> GetAsync(AttachmentEndpointType type, Guid parent, string fileName) { var response = await Client.GetAsync($"{_endpointBase}/{type}/{parent:D}/Attachments/{fileName}").ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.OK) { var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); return(new Attachment(stream, fileName, response.Content.Headers.ContentType.ToString(), (int)stream.Length)); } await Client.HandleErrorsAsync(response).ConfigureAwait(false); return(null); }
public async Task <Attachment> AddOrReplaceAsync(Attachment attachment, AttachmentEndpointType type, Guid parent, bool includeOnline = false) { var mimeType = MimeTypes.GetMimeType(attachment.FileName); var url = $"{_endpointBase}/{type}/{parent:D}/Attachments/{attachment.FileName}"; var parameters = new NameValueCollection(); if (SupportsOnline(type) && includeOnline) { parameters.AddIfNotNull("IncludeOnline", true); } var result = await Client.PostAsync <Attachment, AttachmentsResponse>(url, attachment.Content, mimeType, parameters).ConfigureAwait(false); return(result.FirstOrDefault()); }
public async Task <Attachment> AddOrReplaceAsync(Attachment attachment, AttachmentEndpointType type, Guid parent, bool includeOnline = false) { var mimeType = MimeTypes.GetMimeType(attachment.FileName); var url = string.Format("/api.xro/2.0/{0}/{1}/Attachments/{2}", type, parent.ToString("D"), attachment.FileName); var parameters = new NameValueCollection(); if (SupportsOnline(type) && includeOnline) { parameters.Add("IncludeOnline", true); } var result = await Client.PostAsync <Attachment, AttachmentsResponse>(url, attachment.Content, mimeType, parameters); return(result.FirstOrDefault()); }
private static bool SupportsOnline(AttachmentEndpointType type) { return(type == AttachmentEndpointType.Invoices || type == AttachmentEndpointType.CreditNotes); }
private Attachment CreateAttachment(Guid id, AttachmentEndpointType type, FileInfo sourceFile, bool includeOnline = false) { return(Api.Attachments.AddOrReplace(new Attachment(sourceFile), type, id, includeOnline)); }
private Attachment GetAttachment(Guid id, AttachmentEndpointType type, string fileName) { return(Api.Attachments.Get(type, id, fileName)); }
public virtual IEnumerable <Attachment> List(AttachmentEndpointType type, Guid parent) { return(Client.Get <Attachment, AttachmentsResponse>(string.Format("/api.xro/2.0/{0}/{1}/Attachments", type, parent.ToString("D")))); }
private Task<Attachment> GetAttachment(Guid id, AttachmentEndpointType type, string fileName) { return Api.Attachments.GetAsync(type, id, fileName); }
private Task<Attachment> CreateAttachment(Guid id, AttachmentEndpointType type, FileInfo sourceFile, bool includeOnline = false) { return Api.Attachments.AddOrReplaceAsync(new Attachment(sourceFile), type, id, includeOnline); }
private async Task <Attachment> GetAttachment(Guid id, AttachmentEndpointType type, string fileName) { return(await Api.Attachments.GetAsync(type, id, fileName)); }
private Attachment GetAttachment(Guid id, AttachmentEndpointType type, string fileName) { return Api.Attachments.Get(type, id, fileName); }
public Task <IEnumerable <Attachment> > ListAsync(AttachmentEndpointType type, Guid parent) { return(Client.GetAsync <Attachment, AttachmentsResponse>($"{_endpointBase}/{type}/{parent:D}/Attachments")); }
public async Task <IEnumerable <Attachment> > ListAsync(AttachmentEndpointType type, Guid parent) { return(await Client.GetAsync <Attachment, AttachmentsResponse>(string.Format("/api.xro/2.0/{0}/{1}/Attachments", type, parent.ToString("D")))); }
public IEnumerable<Attachment> List(AttachmentEndpointType type, Guid parent) { return Client.Get<Attachment, AttachmentsResponse>(string.Format("/api.xro/2.0/{0}/{1}/Attachments", type, parent.ToString("D"))); }
private async Task <Attachment> CreateAttachment(Guid id, AttachmentEndpointType type, bool includeOnline = false) { return(await CreateAttachment(id, type, new FileInfo(ImagePath), includeOnline)); }
private Task<Attachment> CreateAttachment(Guid id, AttachmentEndpointType type, bool includeOnline = false) { return CreateAttachment(id, type, new FileInfo(ImagePath), includeOnline); }
private static bool SupportsOnline(AttachmentEndpointType type) { return type == AttachmentEndpointType.Invoices || type == AttachmentEndpointType.CreditNotes; }
private async Task <Attachment> CreateAttachment(Guid id, AttachmentEndpointType type, FileInfo sourceFile, bool includeOnline = false) { return(await Api.Attachments.AddOrReplaceAsync(new Attachment(sourceFile), type, id, includeOnline)); }