コード例 #1
0
        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 AssetAssignmentsViewItemProxy[] GetAssetAssignments(int assetID)
        {
            AssetAssignmentsView assetAssignments = new AssetAssignmentsView(TSAuthentication.GetLoginUser());

            assetAssignments.LoadByAssetID(assetID);
            List <AssetAssignmentsViewItemProxy> result = new List <AssetAssignmentsViewItemProxy>();

            foreach (AssetAssignmentsViewItem assetAssignment in assetAssignments)
            {
                result.Add(assetAssignment.GetProxy());
            }
            return(result.ToArray());
        }
コード例 #3
0
        public static string GetAssetAssignmentsView(RestCommand command, int assetID)
        {
            AssetAssignmentsView assetAssignmentsView = new AssetAssignmentsView(command.LoginUser);

            assetAssignmentsView.LoadByAssetID(assetID);

            if (command.Format == RestFormat.XML)
            {
                return(assetAssignmentsView.GetXml("AssetAssignments", "AssetAssignment", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
コード例 #4
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));
        }
コード例 #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["AssetID"] == null)
        {
            EndResponse("Invalid Asset");
        }

        int       assetID   = int.Parse(Request["AssetID"]);
        LoginUser loginUser = TSAuthentication.GetLoginUser();
        Asset     asset     = Assets.GetAsset(loginUser, assetID);

        if (asset == null)
        {
            EndResponse("Invalid Asset");
        }

        if (asset.OrganizationID != TSAuthentication.OrganizationID)
        {
            EndResponse("Invalid Asset");
        }

        tipAsset.InnerText = asset.Name;
        tipAsset.Attributes.Add("onclick", "top.Ts.MainPage.openAsset(" + assetID.ToString() + "); return false;");

        StringBuilder props = new StringBuilder();

        if (!string.IsNullOrEmpty(asset.SerialNumber))
        {
            props.Append(string.Format("<dt>{0}</dt><dd>{1}</dd>", "Serial Number", asset.SerialNumber));
        }
        if (!string.IsNullOrEmpty(asset.Location))
        {
            props.Append(string.Format("<dt>{0}</dt><dd>{1}</dd>", "Location", asset.Location));
        }
        switch (asset.Location.Trim())
        {
        case "1": props.Append("<dt>Location</dt><dd>Assigned</dd>"); break;

        case "2": props.Append("<dt>Location</dt><dd>Warehouse</dd>"); break;

        case "3": props.Append("<dt>Location</dt><dd>Junkyard</dd>"); break;

        default: props.Append("<dt>Location</dt><dd>Unknown</dd>"); break;
        }
        if (!string.IsNullOrEmpty(asset.Status))
        {
            props.Append(string.Format("<dt>{0}</dt><dd>{1}</dd>", "Status", asset.Status));
        }
        if (asset.WarrantyExpiration != null)
        {
            props.Append(string.Format("<dt>{0:d}</dt><dd>{1}</dd>", "Warranty Expiration", (DateTime)asset.WarrantyExpiration));
        }

        if (asset.ProductID != null)
        {
            Product product = Products.GetProduct(loginUser, (int)asset.ProductID);
            if (product != null)
            {
                props.Append(string.Format("<dt>{0}</dt><dd>{1}</dd>", "Product", product.Name));
            }
        }

        if (asset.Location.Trim() == "1")
        {
            AssetAssignmentsView assetAssignments = new AssetAssignmentsView(loginUser);
            assetAssignments.LoadByAssetID(assetID);
            if (assetAssignments.Count > 0)
            {
                props.Append(string.Format("<dt>{0}</dt><dd>{1}</dd>", "Assigned To", assetAssignments[0].NameAssignedTo));
            }
        }


        if (!string.IsNullOrEmpty(asset.Notes))
        {
            props.Append(string.Format("<dt>{0}</dt><dd>{1}</dd>", "Notes", asset.Notes));
        }

        tipProps.InnerHtml = props.ToString();
    }
コード例 #6
0
        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);
        }
コード例 #7
0
        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));
        }