public AssetHistoryViewItemProxy[] LoadHistory(int assetID, int start) { AssetHistoryView history = new AssetHistoryView(TSAuthentication.GetLoginUser()); history.LoadByAssetIDLimit(assetID, start); return(history.GetAssetHistoryViewItemProxies()); }
public static string GetAssetHistoryViewItem(RestCommand command, int historyID) { AssetHistoryViewItem assetHistoryViewItem = AssetHistoryView.GetAssetHistoryViewItem(command.LoginUser, historyID); if (assetHistoryViewItem.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(assetHistoryViewItem.GetXml("AssetHistoryViewItem", true)); }
public static string GetAssetHistoryView(RestCommand command, int assetID) { AssetHistoryView assetHistoryView = new AssetHistoryView(command.LoginUser); assetHistoryView.LoadByAssetID(assetID); if (command.Format == RestFormat.XML) { return(assetHistoryView.GetXml("AssetHistory", "AssetHistoryItem", true, command.Filters)); } else { throw new RestException(HttpStatusCode.BadRequest, "Invalid data format"); } }
public static string ReturnAsset(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 != "1") { throw new RestException(HttpStatusCode.BadRequest, "Only assigned assets can be returned."); } AssetAssignmentsView assetAssignmentsView = new AssetAssignmentsView(command.LoginUser); assetAssignmentsView.LoadByAssetID(assetID); AssetHistory assetHistory = new AssetHistory(command.LoginUser); AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem(); //Html specification does not allow body being send in the DELETE method. //Nevertheless, is relevant as in addition to deleting the assignments we are also adding a history record indicating shipping data. //If no body is sent an exception will be thrown as the Shipping Date is required by the webapp. try { assetHistoryItem.ReadFromXml(command.Data, true); } catch (Exception) { throw new RestException(HttpStatusCode.BadRequest, "Please include a request body with an <AssetHistoryItem> node including at least an <ActionDescription> including the Date Shipped and a <ShippingMethod> node with a valid value."); } ValidateReturn(assetHistoryItem); //Update Asset. asset.Location = "2"; asset.AssignedTo = null; DateTime now = DateTime.UtcNow; asset.DateModified = now; asset.ModifierID = command.LoginUser.UserID; asset.Collection.Save(); //Add history record. assetHistoryItem.AssetID = assetID; assetHistoryItem.OrganizationID = command.LoginUser.OrganizationID; assetHistoryItem.ActionTime = now; assetHistoryItem.ShippedFrom = assetAssignmentsView[0].ShippedTo; assetHistoryItem.ShippedFromRefType = assetAssignmentsView[0].RefType; assetHistoryItem.ShippedTo = command.LoginUser.OrganizationID; assetHistoryItem.RefType = (int)ReferenceType.Organizations; assetHistoryItem.DateCreated = now; assetHistoryItem.Actor = command.LoginUser.UserID; assetHistoryItem.DateModified = now; assetHistoryItem.ModifierID = command.LoginUser.UserID; assetHistory.Save(); //Delete assignments AssetAssignments assetAssignments = new AssetAssignments(command.LoginUser); foreach (AssetAssignmentsViewItem assetAssignmentViewItem in assetAssignmentsView) { assetAssignments.DeleteFromDB(assetAssignmentViewItem.AssetAssignmentsID); } return(AssetHistoryView.GetAssetHistoryViewItem(command.LoginUser, assetHistoryItem.HistoryID).GetXml("AssetHistoryItem", true)); }
override protected void GetNextRecord() { AssetsViewItem asset = AssetsView.GetAssetsViewItem(_loginUser, _itemIDList[_rowIndex]); _lastItemID = asset.AssetID; UpdatedItems.Add((int)_lastItemID); StringBuilder builder = new StringBuilder(); builder.AppendLine(asset.CreatorName + " " + asset.DisplayName + " " + asset.DateCreated + " " + asset.DateModified + " " + asset.ModifierName + " " + asset.Notes + " " + asset.ProductName + " " + asset.ProductVersionNumber + " " + asset.SerialNumber + " " + asset.WarrantyExpiration); AssetHistoryView assetHistoryView = new AssetHistoryView(_loginUser); assetHistoryView.LoadByAssetID(asset.AssetID); foreach (AssetHistoryViewItem assetHistoryViewItem in assetHistoryView) { builder.AppendLine(assetHistoryViewItem.ActionTime + " " + assetHistoryViewItem.ActionDescription + " " + assetHistoryViewItem.NameAssignedFrom + " " + assetHistoryViewItem.NameAssignedTo + " " + assetHistoryViewItem.TrackingNumber + " " + assetHistoryViewItem.ShippingMethod + " " + assetHistoryViewItem.ReferenceNum + " " + assetHistoryViewItem.Comments + " " + assetHistoryViewItem.ActorName + " " + assetHistoryViewItem.DateModified + " " + assetHistoryViewItem.ModifierName + " " + assetHistoryViewItem.DateCreated); } DocText = builder.ToString(); StringBuilder assetLocationString = new StringBuilder(); switch (asset.Location) { case "1": assetLocationString.Append("Assigned"); break; case "2": assetLocationString.Append("Warehouse"); break; case "3": assetLocationString.Append("Junkyard"); break; } _docFields.Clear(); AddDocField("AssetID", asset.AssetID); AddDocField("Location", assetLocationString.ToString()); AddDocField("SerialNumber", asset.SerialNumber); if (string.IsNullOrWhiteSpace(asset.Name)) { if (string.IsNullOrWhiteSpace(asset.SerialNumber)) { AddDocField("Name", asset.AssetID); DocDisplayName = asset.AssetID.ToString(); } else { AddDocField("Name", asset.SerialNumber); DocDisplayName = asset.SerialNumber; } } else { AddDocField("Name", asset.Name); DocDisplayName = asset.Name; } InventorySearchAsset assetItem = new InventorySearchAsset(asset); AddDocField("**JSON", JsonConvert.SerializeObject(assetItem)); CustomValues customValues = new CustomValues(_loginUser); customValues.LoadByReferenceType(_organizationID, ReferenceType.Assets, asset.AssetID); foreach (CustomValue value in customValues) { object o = value.Row["CustomValue"]; string s = o == null || o == DBNull.Value ? "" : o.ToString(); AddDocField(value.Row["Name"].ToString(), s); } DocFields = _docFields.ToString(); DocIsFile = false; DocName = asset.AssetID.ToString(); try { DocCreatedDate = (DateTime)asset.Row["DateCreated"]; DocModifiedDate = (DateTime)asset.Row["DateModified"]; } catch (Exception) { } }
public static string JunkAsset(RestCommand command, int assetID) { Asset asset = Assets.GetAsset(command.LoginUser, assetID); if (asset.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } if (asset.Location == "1") { throw new RestException(HttpStatusCode.BadRequest, "Please return an asset to the Warehouse before sending it to the Junkyard."); } if (asset.Location == "3") { throw new RestException(HttpStatusCode.BadRequest, "This asset is already in the Junkyard."); } asset.Location = "3"; asset.AssignedTo = null; DateTime now = DateTime.UtcNow; asset.DateModified = now; asset.ModifierID = command.LoginUser.UserID; asset.Collection.Save(); AssetHistory assetHistory = new AssetHistory(command.LoginUser); AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem(); //Html specification does not allow body being send in the DELETE method. //Nevertheless, is relevant as we are not really deleting and we need to add a delete comment. //If no body is sent an exception will be thrown. We ignore it to allow sending to junkyard without a comment. try { assetHistoryItem.ReadFromXml(command.Data, true); } catch (Exception) { } assetHistoryItem.AssetID = assetID; assetHistoryItem.OrganizationID = command.LoginUser.OrganizationID; assetHistoryItem.ActionTime = now; assetHistoryItem.ActionDescription = "Asset assigned to Junkyard via API."; assetHistoryItem.ShippedFrom = -1; assetHistoryItem.ShippedFromRefType = -1; assetHistoryItem.ShippedTo = -1; assetHistoryItem.RefType = -1; assetHistoryItem.TrackingNumber = string.Empty; assetHistoryItem.ShippingMethod = string.Empty; assetHistoryItem.ReferenceNum = string.Empty; //This is handled by the ReadFromXml //assetHistoryItem.Comments = comments; assetHistoryItem.DateCreated = now; assetHistoryItem.Actor = command.LoginUser.UserID; assetHistoryItem.DateModified = now; assetHistoryItem.ModifierID = command.LoginUser.UserID; assetHistory.Save(); return(AssetHistoryView.GetAssetHistoryViewItem(command.LoginUser, assetHistoryItem.HistoryID).GetXml("AssetHistoryItem", true)); }