public static string GetAssetAssignmentsViewItem(RestCommand command, int assetAssignmentsID)
        {
            AssetAssignmentsViewItem assetAssignmentsViewItem = AssetAssignmentsView.GetAssetAssignmentsViewItem(command.LoginUser, assetAssignmentsID);

            if (assetAssignmentsViewItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(assetAssignmentsViewItem.GetXml("AssetAssignmentsViewItem", true));
        }
Пример #2
0
        public static string AddAssetAssignment(RestCommand command, int assetID)
        {
            Asset asset = Assets.GetAsset(command.LoginUser, assetID);

            if (asset == null || asset.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            if (asset.Location == "3")
            {
                throw new RestException(HttpStatusCode.Forbidden, "Junkyard assets cannot be assigned. Please move it to the Warehouse before assigning it.");
            }

            AssetHistory     assetHistory     = new AssetHistory(command.LoginUser);
            AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem();

            assetHistoryItem.FullReadFromXml(command.Data, true);

            ValidateAssignment(command.LoginUser, assetHistoryItem);

            DateTime now = DateTime.UtcNow;

            assetHistoryItem.AssetID            = assetID;
            assetHistoryItem.OrganizationID     = command.LoginUser.OrganizationID;
            assetHistoryItem.ActionTime         = now;
            assetHistoryItem.ShippedFrom        = command.LoginUser.OrganizationID;
            assetHistoryItem.ShippedFromRefType = (int)ReferenceType.Organizations;
            assetHistoryItem.DateCreated        = now;
            assetHistoryItem.Actor        = command.LoginUser.UserID;
            assetHistoryItem.DateModified = now;
            assetHistoryItem.ModifierID   = command.LoginUser.UserID;
            assetHistory.Save();

            AssetAssignments assetAssignments = new AssetAssignments(command.LoginUser);
            AssetAssignment  assetAssignment  = assetAssignments.AddNewAssetAssignment();

            assetAssignment.HistoryID = assetHistoryItem.HistoryID;
            assetAssignments.Save();

            asset.Location   = "1";
            asset.AssignedTo = assetHistoryItem.ShippedTo;
            asset.Collection.Save();

            return(AssetAssignmentsView.GetAssetAssignmentsViewItem(command.LoginUser, assetAssignment.AssetAssignmentsID).GetXml("AssetAssignment", true));
        }