public static string GetAssetAssignment(RestCommand command, int assetAssignmentsID) { AssetAssignment assetAssignment = AssetAssignments.GetAssetAssignment(command.LoginUser, assetAssignmentsID); if (assetAssignment.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(assetAssignment.GetXml("AssetAssignment", true)); }
public static string GetAssetAssignments(RestCommand command) { AssetAssignments assetAssignments = new AssetAssignments(command.LoginUser); assetAssignments.LoadByOrganizationID(command.Organization.OrganizationID); if (command.Format == RestFormat.XML) { return(assetAssignments.GetXml("AssetAssignments", "AssetAssignment", true, command.Filters)); } else { throw new RestException(HttpStatusCode.BadRequest, "Invalid data format"); } }
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)); }
public int ReturnAsset(int assetID, string data) { AssignAssetSave info; try { info = Newtonsoft.Json.JsonConvert.DeserializeObject <AssignAssetSave>(data); } catch (Exception e) { return(-1); } LoginUser loginUser = TSAuthentication.GetLoginUser(); Asset o = Assets.GetAsset(loginUser, assetID); //Location 1=assigned (shipped), 2=warehouse, 3=junkyard o.Location = "2"; o.AssignedTo = null; DateTime now = DateTime.UtcNow; o.DateModified = now; o.ModifierID = loginUser.UserID; o.Collection.Save(); AssetAssignmentsView assetAssignmentsView = new AssetAssignmentsView(loginUser); assetAssignmentsView.LoadByAssetID(assetID); AssetHistory assetHistory = new AssetHistory(loginUser); AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem(); assetHistoryItem.AssetID = assetID; assetHistoryItem.OrganizationID = loginUser.OrganizationID; assetHistoryItem.ActionTime = DateTime.UtcNow; assetHistoryItem.ActionDescription = "Item returned to warehouse on " + info.DateShipped.Month.ToString() + "/" + info.DateShipped.Day.ToString() + "/" + info.DateShipped.Year.ToString(); assetHistoryItem.ShippedFrom = assetAssignmentsView[0].ShippedTo; assetHistoryItem.ShippedFromRefType = assetAssignmentsView[0].RefType; assetHistoryItem.ShippedTo = loginUser.OrganizationID; assetHistoryItem.RefType = (int)ReferenceType.Organizations; assetHistoryItem.TrackingNumber = info.TrackingNumber; assetHistoryItem.ShippingMethod = info.ShippingMethod; assetHistoryItem.ReferenceNum = info.ReferenceNumber; assetHistoryItem.Comments = info.Comments; assetHistoryItem.DateCreated = now; assetHistoryItem.Actor = loginUser.UserID; assetHistoryItem.DateModified = now; assetHistoryItem.ModifierID = loginUser.UserID; assetHistory.Save(); AssetAssignments assetAssignments = new AssetAssignments(loginUser); foreach (AssetAssignmentsViewItem assetAssignmentViewItem in assetAssignmentsView) { assetAssignments.DeleteFromDB(assetAssignmentViewItem.AssetAssignmentsID); } ActionLogs.AddActionLog(loginUser, ActionLogType.Update, ReferenceType.Assets, assetID, "Returned asset."); return(assetID); }
public string AssignAsset(int assetID, string data) { AssignAssetSave info; try { info = Newtonsoft.Json.JsonConvert.DeserializeObject <AssignAssetSave>(data); } catch (Exception e) { return("error"); } LoginUser loginUser = TSAuthentication.GetLoginUser(); Asset o = Assets.GetAsset(loginUser, assetID); //Location 1=assigned (shipped), 2=warehouse, 3=junkyard o.Location = "1"; o.AssignedTo = info.RefID; DateTime now = DateTime.UtcNow; o.DateModified = now; o.ModifierID = loginUser.UserID; o.Collection.Save(); AssetHistory assetHistory = new AssetHistory(loginUser); AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem(); assetHistoryItem.AssetID = assetID; assetHistoryItem.OrganizationID = loginUser.OrganizationID; assetHistoryItem.ActionTime = DateTime.UtcNow; assetHistoryItem.ActionDescription = "Asset Shipped on " + info.DateShipped.Month.ToString() + "/" + info.DateShipped.Day.ToString() + "/" + info.DateShipped.Year.ToString(); assetHistoryItem.ShippedFrom = loginUser.OrganizationID; assetHistoryItem.ShippedFromRefType = (int)ReferenceType.Organizations; assetHistoryItem.ShippedTo = info.RefID; assetHistoryItem.TrackingNumber = info.TrackingNumber; assetHistoryItem.ShippingMethod = info.ShippingMethod; assetHistoryItem.ReferenceNum = info.ReferenceNumber; assetHistoryItem.Comments = info.Comments; assetHistoryItem.DateCreated = now; assetHistoryItem.Actor = loginUser.UserID; assetHistoryItem.RefType = info.RefType; assetHistoryItem.DateModified = now; assetHistoryItem.ModifierID = loginUser.UserID; assetHistory.Save(); AssetAssignments assetAssignments = new AssetAssignments(loginUser); AssetAssignment assetAssignment = assetAssignments.AddNewAssetAssignment(); assetAssignment.HistoryID = assetHistoryItem.HistoryID; assetAssignments.Save(); string description = String.Format("Assigned asset to {0}.", info.AssigneeName); ActionLogs.AddActionLog(loginUser, ActionLogType.Update, ReferenceType.Assets, assetID, description); AssetsView assetsView = new AssetsView(loginUser); assetsView.LoadByAssetID(assetID); StringBuilder productVersionNumberDisplayName = new StringBuilder(); if (!string.IsNullOrEmpty(assetsView[0].ProductVersionNumber)) { productVersionNumberDisplayName.Append(" - " + assetsView[0].ProductVersionNumber); } StringBuilder serialNumberDisplayValue = new StringBuilder(); if (string.IsNullOrEmpty(assetsView[0].SerialNumber)) { serialNumberDisplayValue.Append("Empty"); } else { serialNumberDisplayValue.Append(assetsView[0].SerialNumber); } StringBuilder warrantyExpirationDisplayValue = new StringBuilder(); if (assetsView[0].WarrantyExpiration == null) { warrantyExpirationDisplayValue.Append("Empty"); } else { warrantyExpirationDisplayValue.Append(((DateTime)assetsView[0].WarrantyExpiration).ToString(GetDateFormatNormal())); } return(string.Format(@"<div class='list-group-item'> <a href='#' id='{0}' class='assetLink'><h4 class='list-group-item-heading'>{1}</h4></a> <div class='row'> <div class='col-xs-8'> <p class='list-group-item-text'>{2}{3}</p> </div> </div> <div class='row'> <div class='col-xs-8'> <p class='list-group-item-text'>SN: {4} - Warr. Exp.: {5}</p> </div> </div> </div>" , assetID , assetsView[0].DisplayName , assetsView[0].ProductName , productVersionNumberDisplayName , serialNumberDisplayValue , warrantyExpirationDisplayValue)); }
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)); }