Пример #1
0
        /// <summary>
        /// Marks an asset as audited.
        /// </summary>
        /// <param name="asset">An asset to audit.</param>
        /// <param name="location">The location of the audit.</param>
        /// <param name="nextAuditDate">The date of the next audit.</param>
        /// <param name="notes">A note for the audit log.</param>
        /// <returns>An <see cref="AssetAudit"/> with some fields missing, and the request status.</returns>
        public RequestResponse <AssetAudit> Audit(Asset asset, Location location = null, DateTime?nextAuditDate = null, string notes = null)
        {
            var audit = new AssetAudit
            {
                Asset         = asset,
                Location      = location,
                NextAuditDate = nextAuditDate,
                Note          = notes
            };

            return(Api.RequestManager.Post <AssetAudit>($"{EndPointInfo.BaseUri}/audit", audit).RethrowExceptionIfAny().Value);
        }
Пример #2
0
        private void SaveAssets(List <Asset> allAssets, Asset oldAsset, Asset newAsset, string actionName)
        {
            var oldAssets = allAssets.ToArray();

            var lastUpdatedTime = DateTime.Now;

            switch (actionName)
            {
            case AddAssetAction:
                // set timestamp
                newAsset.LastUpdatedTime = lastUpdatedTime;
                allAssets.Add(newAsset);
                break;

            case UpdateAssetAction:
                allAssets.Remove(oldAsset);

                // set timestamp
                newAsset.LastUpdatedTime = lastUpdatedTime;
                allAssets.Add(newAsset);

                // check if AssetName has been changed
                if (oldAsset.AssetName != newAsset.AssetName)
                {
                    allAssets
                    .Where(x => x.AssetName == oldAsset.AssetName)
                    .ToList()
                    .ForEach(asset =>
                    {
                        var updatedAsset = asset with {
                            AssetName       = newAsset.AssetName,
                            LastUpdatedTime = lastUpdatedTime
                        };
                        allAssets.Remove(asset);
                        allAssets.Add(updatedAsset);
                    });
                }

                break;

            case DeleteAssetAction:
                allAssets.Remove(oldAsset);
                break;

            default:
                throw new Exception($"Action is not supported - {actionName}");
            }

            var newAssets =
                allAssets
                .OrderBy(x => x.AssetType)
                .ThenBy(x => x.AssetName)
                .ThenByDescending(x => x.AssetDate)
                .ThenByDescending(x => x.LastUpdatedTime)
                .ToArray();

            // Backup the changes
            var assetAudit = new AssetAudit(actionName, oldAsset, newAsset, oldAssets, newAssets);

            File.WriteAllText(AuditFilePath, JsonSerializer.Serialize(assetAudit));

            // Save to the current file path
            File.WriteAllText(CurrentFilePath, JsonSerializer.Serialize(newAssets));
        }