-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #445 from bostick23/master
Added AttachmentFactory
- Loading branch information
Showing
5 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
PrestaSharp/Entities/AuxEntities/AssociationsAttachments.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Serialization; | ||
|
||
namespace Bukimedia.PrestaSharp.Entities.AuxEntities | ||
{ | ||
[XmlType(Namespace = "Bukimedia/PrestaSharp/Entities/AuxEntities")] | ||
public class AssociationsAttachments : PrestaShopEntity | ||
{ | ||
public List<AuxEntities.products> products { get; set; } | ||
public AssociationsAttachments() | ||
{ | ||
products = new List<products>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Serialization; | ||
|
||
namespace Bukimedia.PrestaSharp.Entities.AuxEntities | ||
{ | ||
[XmlType(Namespace = "Bukimedia/PrestaSharp/Entities/AuxEntities")] | ||
public class attachment : GenericAssociation | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Bukimedia.PrestaSharp.Entities.AuxEntities; | ||
using RestSharp.Serializers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Serialization; | ||
|
||
namespace Bukimedia.PrestaSharp.Entities | ||
{ | ||
[XmlType(Namespace = "Bukimedia/PrestaSharp/Entities")] | ||
public class attachment : PrestaShopEntity | ||
{ | ||
public long id { get; set; } | ||
public string file { get; set; } | ||
public string file_name { get; set; } | ||
public long file_size { get; set; } | ||
public string mime { get; set; } | ||
public List<AuxEntities.language> name { get; set; } | ||
public List<AuxEntities.language> description { get; set; } | ||
public AssociationsAttachments associations { get; set; } | ||
|
||
public attachment() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Bukimedia.PrestaSharp.Entities; | ||
using Bukimedia.PrestaSharp.Factories; | ||
using RestSharp; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Mail; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Bukimedia.PrestaSharp.Factories | ||
{ | ||
public class AttachmentFactory : RestSharpFactory | ||
{ | ||
public AttachmentFactory(string BaseUrl, string Account, string SecretKey) | ||
: base(BaseUrl, Account, SecretKey) | ||
{ | ||
} | ||
|
||
#region Protected methods | ||
|
||
public List<Entities.attachment> GetAllAttachments() | ||
{ | ||
RestRequest request = this.RequestForFilter("attachments/", "full", null, null, null, "attachments"); | ||
return this.Execute<List<Entities.attachment>>(request); | ||
} | ||
public Entities.attachment GetAttachmentByInstance(long Id) | ||
{ | ||
RestRequest request = this.RequestForFilter("attachments/" + Id, null, null, null, null, "attachments"); | ||
Entities.attachment obj = this.Execute<List<Entities.attachment>>(request)?.First() ?? null; | ||
return obj; | ||
} | ||
public Entities.attachment AddAttachmentFile(string filePath) | ||
{ | ||
RestRequest request = this.RequestForAddAttachment(filePath); | ||
return this.ExecuteForAttachment<Entities.attachment>(request); | ||
} | ||
|
||
public Entities.attachment UpdateAttachmentFile(long id, string filePath) | ||
{ | ||
RestRequest request = this.RequestForUpdateAttachment(filePath, id); | ||
return this.ExecuteForAttachment<Entities.attachment>(request); | ||
} | ||
public void DeleteAttachment(long id) | ||
{ | ||
RestRequest request = this.RequestForDelete("attachments", id); | ||
this.Execute<Entities.attachment>(request); | ||
} | ||
|
||
#endregion | ||
#region Public Methods | ||
public Entities.attachment UpdateAttachment(attachment attachment) | ||
{ | ||
RestRequest request = this.RequestForUpdate("attachments", attachment.id, attachment); | ||
return this.Execute<Entities.attachment>(request); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters