diff --git a/SnipeSharp/EndPoint/ComponentEndPoint.cs b/SnipeSharp/EndPoint/ComponentEndPoint.cs index 9661474..d523b1b 100644 --- a/SnipeSharp/EndPoint/ComponentEndPoint.cs +++ b/SnipeSharp/EndPoint/ComponentEndPoint.cs @@ -9,7 +9,7 @@ public sealed class ComponentEndPoint : EndPoint { /// The Api to grab the RequestManager from. /// When the type parameter does not have the PathSegmentAttribute attribute. - internal ComponentEndPoint(SnipeItApi api) : base(api) {} + internal ComponentEndPoint(SnipeItApi api) : base(api) { } /// /// Get the list of component assignees for a component. @@ -18,5 +18,25 @@ internal ComponentEndPoint(SnipeItApi api) : base(api) {} /// A ResponseCollection list of ComponentAssignees. public ResponseCollection GetAssignedAssets(Component component) => Api.RequestManager.GetAll($"{EndPointInfo.BaseUri}/{component.Id}/assets").RethrowExceptionIfAny().Value; + + /// + /// Check out an accessory. + /// + /// An accessory check-out request. + /// + public RequestResponse CheckOut(ComponentCheckOutRequest request) + => Api.RequestManager.Post($"{EndPointInfo.BaseUri}/{request.Component.Id}/checkout", request).RethrowExceptionIfAny().Value; + + + /// + /// Check out a component. + /// + /// The accessory to check out. + /// The user to check out to. + /// /// How many components should be assigned to the asset. + /// An optional note for the checkout log. + /// + public RequestResponse CheckOut(Component component, Asset assignedAsset, int quantity, string note = null) + => CheckOut(new ComponentCheckOutRequest(component, assignedAsset, quantity) { Note = note }); } } diff --git a/SnipeSharp/Models/ComponentCheckOut.cs b/SnipeSharp/Models/ComponentCheckOut.cs new file mode 100644 index 0000000..e808fb1 --- /dev/null +++ b/SnipeSharp/Models/ComponentCheckOut.cs @@ -0,0 +1,36 @@ +using SnipeSharp.Serialization; +using SnipeSharp.Models.Enumerations; + +namespace SnipeSharp.Models +{ + /// + /// A Componenet/Asset relation. + /// + public sealed class ComponentCheckOut : ApiObject, IAvailableActions + { + /// + /// The Id of the Component in Snipe-IT. + /// + [DeserializeAs("assigned_pivot_id")] + public int ComponentId { get; private set; } + + /// + /// The Id of the User in Snipe-IT. + /// + [DeserializeAs("id")] + public int AssetId { get; private set; } + + + /// + /// The assignee type of this particular check out. + /// + /// Currently, this field will always be Asset. + [DeserializeAs("type")] + public AssignedToType Type { get; private set; } + + /// + /// Currently, this will always be {CheckIn}. + [DeserializeAs("available_actions", DeserializeAs.AvailableActions)] + public AvailableAction AvailableActions { get; private set; } + } +} diff --git a/SnipeSharp/Models/OnlySubmittable/ComponentCheckOutRequest.cs b/SnipeSharp/Models/OnlySubmittable/ComponentCheckOutRequest.cs new file mode 100644 index 0000000..af64c11 --- /dev/null +++ b/SnipeSharp/Models/OnlySubmittable/ComponentCheckOutRequest.cs @@ -0,0 +1,39 @@ +using SnipeSharp.Serialization; + +namespace SnipeSharp.Models +{ + /// + /// A request to associate an Accessory with a User. + /// + public sealed class ComponentCheckOutRequest : ApiObject + { + /// The Accessory that will be checked out. + /// This property is not serialized, but instead used for its Id value. + public Component Component { get; private set; } + + /// The assigned user. + [SerializeAs("assigned_to", SerializeAs.IdValue)] + public Asset AssignedAsset { get; private set; } + + /// The note to put in the log for this check-out event. + [SerializeAs("note")] + public string Note { get; set; } + + ///How many to assign + [SerializeAs("assigned_qty")] + public int Quantity { get; set; } + + /// + /// Begins a new ComponentCheckOutRequest assigning the supplied component to the supplied asset. + /// + /// The accessory to assign. + /// The User to assign the accessory to. + /// How many components to assign to the asset + public ComponentCheckOutRequest(Component component, Asset asset, int quantity) + { + Component = component; + AssignedAsset = asset; + Quantity = quantity; + } + } +}