Exemplo n.º 1
0
    protected void SqlAsset_OnUpdated(object sender, SqlDataSourceStatusEventArgs e)
    {
        var updatedAsset = GetAssetFromDb();

        if (updatedAsset == null)
        {
            return;
        }

        try
        {
            if (string.Compare(editedAsset.ClientID, updatedAsset.ClientID, StringComparison.InvariantCulture) != 0 || editedAsset.AssetType != updatedAsset.AssetType || editedAsset.AssetSubType != updatedAsset.AssetSubType)
            {
                if (!RestServiceHelper.InvokePost(editedAsset.ClientID, editedAsset.AssetType, editedAsset.AssetSubType, -1))
                {
                    ErrorMsg.Text = "Asset Updated. Failed to update Global Asset counter Service.";
                }

                if (!RestServiceHelper.InvokePost(updatedAsset.ClientID, updatedAsset.AssetType, updatedAsset.AssetSubType, 1))
                {
                    ErrorMsg.Text = "Asset Updated. Failed to update Global Asset counter Service.";
                }
            }

            if (!RestServiceHelper.InvokePostGlobalAsset(updatedAsset))
            {
                ErrorMsg.Text = "Asset Updated. Failed to update Global Asset Service.";
            }
        }
        catch (Exception exception)
        {
            Debug.WriteLine(exception);
            ErrorMsg.Text = "Asset Updated. Failed to update Global Asset Service." + exception.GetDisplayMessage();
        }
    }
Exemplo n.º 2
0
    protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        string        conString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlConnectionString"].ToString();
        SqlConnection sqlConn   = new SqlConnection(conString);
        object        AssetID;
        SqlCommand    command = new SqlCommand("usp_GetLastAssetID", sqlConn);

        command.CommandType = CommandType.StoredProcedure;
        sqlConn.Open();
        AssetID = command.ExecuteScalar();
        sqlConn.Close();

        string ClientID = ConfigurationManager.AppSettings["SubscriptionID"];

        var newAsset = GetAssetFromDb(Decimal.ToInt32((decimal)AssetID));

        if (newAsset == null)
        {
            return;
        }

        try
        {
            if (!RestServiceHelper.InvokePostGlobalAsset(newAsset))
            {
                ErrorMsg.Text = "Asset Added. Failed to update Global Asset Service.";
            }

            if (!RestServiceHelper.InvokePost(newAsset.ClientID, newAsset.AssetType, newAsset.AssetSubType))
            {
                ErrorMsg.Text = "Asset Added. Failed to update Global Asset Counter Service.";
            }
        }
        catch (Exception exception)
        {
            System.Diagnostics.Trace.WriteLine(exception.Message);
            System.Diagnostics.Trace.WriteLine(exception.InnerException.Message);
            System.Diagnostics.Trace.WriteLine(exception.StackTrace);
            ErrorMsg.Text = "Asset Added. Failed to update Global Asset Counter Service." + exception.GetDisplayMessage();
        }

        string URL = "AssetDetail.aspx?ID=" + Convert.ToString(AssetID);

        if (!string.IsNullOrEmpty(ErrorMsg.Text))
        {
            URL = string.Concat(URL, "&ErrorMessage=", ErrorMsg.Text);
        }

        Response.Redirect(URL);
    }