示例#1
0
        // Return a Model Object with index View and fill the data from Assets / Database
        public ActionResult Index([FromBody] OIDCRequest request)
        {
            // Model Object Declerations
            ParentModel     obj      = new ParentModel();
            Form9035        form     = new Form9035();
            Lists           allLists = new Lists();
            OrchestratorAPI api      = new OrchestratorAPI();
            // Add starting point on ES
            ElasticSearch es     = new ElasticSearch();
            string        bal_no = "";

            ViewBag.id_no = "";
            string errorMessage = "";

            try
            {
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                string            url     = Request.Url.ToString();
                // LOCAL USE : Comment this 2 lines whenever you need to publish and push the code these are only for local use
                // add the case no. and the id no. whenever you're debugging and using this as local
                if (url.Contains("localhost"))
                {
                    //for staging localhost
                    request.State = "'+bal_no=1615.54312.7;id_no=BOT0001711;-5791a545d45a92763d8216ffb7004e3ebc32226af366113cf24975ea00014d51+";
                    //localhost
                    request.State = "'+bal_no=91.147449.2;id_no=43383;-5791a545d45a92763d8216ffb7004e3ebc32226af366113cf24975ea00014d51+";
                    request.Code  = "182635";
                }
                TempData["Error"] = "";
                string filter            = "";
                string encryptedData     = "";
                string decodeData        = "";
                string data              = "";
                string ListencryptedData = "";
                if ((request.Code != null && request.Code != "") && (request.State != null && request.State != ""))
                {
                    // GET The username which try to access this page
                    string sUserName = null;

                    if (url.Contains("localhost"))
                    {
                        sUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                    }
                    else
                    {
                        sUserName = User.Identity.Name;
                    }
                    // Extract the username from the identity
                    Log.Info("The User identity Name is : " + sUserName);
                    string[] spliUser = sUserName.Split('\\');
                    sUserName = spliUser[1];
                    Log.Info("The User Name is : " + sUserName);
                    // Split the request string and extract BAL Number and ID Number
                    string              stateStr    = request.State.ToString().Substring(2);
                    string[]            stateArray  = stateStr.Split('-');
                    string              splitArray  = stateArray[0].Replace(";", "&");
                    NameValueCollection queryString = HttpUtility.ParseQueryString(splitArray);
                    bal_no = queryString["bal_no"].ToString();
                    // Save into ViewBags for JS Use
                    ViewBag.id_no    = queryString["id_no"];
                    ViewBag.bal_no   = bal_no;
                    ViewBag.email_id = sUserName;
                    // Entry point on ES
                    if (es.AddESLog(ViewBag.bal_no, ViewBag.id_no, out errorMessage) == HttpStatusCode.BadRequest)
                    {
                        Log.Info(bal_no + ": Process : Draft9089 -  Error Occurred while Calling ES. See ES Log File for further details");
                    }
                    // Getting UIPATH Token
                    string token = api.Authentication(appKeys.isDevelopmentEnvironment);
                    Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  All variables has been initialized successfully.");
                    // get n check if asset exist
                    filter = "?$filter=Name eq '" + bal_no + "'";
                    AssetModel assetModel = api.GetAsset(token, filter);
                    // Extracting the Encrypted Data String
                    foreach (var item in assetModel.value)
                    {
                        // 9035 Model Value
                        if (!item.Name.Contains("Lists"))
                        {
                            if (encryptedData == "")
                            {
                                encryptedData = item.Value;
                            }
                            else
                            {
                                encryptedData += item.Value;
                            }
                        }
                        // List Model Value
                        else if (item.Name.Contains("Lists"))
                        {
                            if (ListencryptedData == "")
                            {
                                ListencryptedData = item.Value;
                            }
                            else
                            {
                                ListencryptedData += item.Value;
                            }
                        }
                    }
                    // decode and deserialize data if exists form9035 object
                    if (encryptedData != "")
                    {
                        // 9035 Object Decryption
                        decodeData = SecureData.AesDecryptString(appKeys.SecretKey, encryptedData);
                        if (decodeData != "")
                        {
                            data = CompressString.Unzip(decodeData);
                            form = JsonConvert.DeserializeObject <Form9035>(data);
                            Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  Form9035 Data has been decrypted successfully.");
                        }
                    }
                    // List Object Data Decryption
                    if (!string.IsNullOrEmpty(ListencryptedData))
                    {
                        decodeData = SecureData.AesDecryptString(appKeys.SecretKey, ListencryptedData);
                        if (decodeData != "")
                        {
                            data     = CompressString.Unzip(decodeData);
                            allLists = JsonConvert.DeserializeObject <Lists>(data);
                            Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  Lists Data has been decrypted successfully.");
                        }
                    }
                    // if data not exist check from SQL
                    if (assetModel.value.Count <= 0)
                    {
                        //string query = @"select * from BAL9035";
                        // string query = @"select * from BAL9035 where BALNumber='20000.50054.51'";
                        string query = @"select c.CompanyName, c.CompanyNumber, c.IsH1BDependent as 'Company H-1B Dependent', ce.EntityName as 'Sponsoring Entity', ce.IsH1BDependent as 'Entity H-1B Dependent',
                                        b.MatterNumber, b.FullName as 'Beneficiary', b.JobPosition as 'Beneficiary Job Title',
                                        cc.BALNumber, cst.CaseSubType, --max of 6
                                        lca.SocCode, lca.SocOccupation, lca.BeginOfValidity, lca.EndOfValidity, lca.WageRangeLow, lca.WageRangeHigh, lca.WageLevel, lca.NumberOfPositions,
                                        bt1.StaffFirstName as 'Attorney First Name', bt1.StaffMiddleName as 'Attorney Middle Name', bt1.StaffLastName as 'Attorney Last Name', bt1.StaffEmail as 'Attorney Email',
                                        bt2.StaffFirstName as 'Assistant First Name', bt2.StaffMiddleName as 'Assistant Middle Name', bt2.StaffLastName as 'Assistant Last Name', bt2.StaffEmail as 'Assistant Email',
                                        bt3.ContactFirstName as 'Signer First Name', bt3.ContactMiddleName as 'Signer Middle Name', bt3.ContactLastName as 'Signer Last Name', bt3.JobTitle as 'Signer Job',
                                        ca.AddressLine1, ca.AddressLine2, ca.Suite, ca.City, ca.State, ca.ZipCode, l.PrevailingWage, l.PrevailingWageSource, l.PrevailingWagePublishedYear, l.PrevailingWageOther,
                                        p.BALNumber as 'Parent Case Number', ps.CaseSubType as 'ParentCaseSubType'
                                        from ClientCase cc
                                        inner join Beneficiary b on b.beneid = cc.BeneId
                                        inner join Company c on c.CompanyId = b.CompanyId
                                        inner join LCADetail lca on lca.CaseId = cc.CaseId
                                        left join CompanyEntity ce on ce.CompanyEntityId = cc.SponsorEntityId
                                        inner join casecontacts cc1 (nolock) on cc.caseid = cc1.caseid and cc1.casecontacttype = 'BAL_MANAGER' and cc1.isprimary = 1
                                        inner join balteam bt1 (nolock) on cc1.userid = bt1.userid
                                        inner join casecontacts cc2 (nolock) on cc.caseid = cc2.caseid and cc2.casecontacttype = 'BAL_ASSISTANT' and cc2.isprimary = 1
                                        inner join balteam bt2 (nolock) on cc2.userid = bt2.userid
                                        left join casecontacts cc3 (nolock) on cc.caseid = cc3.caseid and cc3.casecontacttype = 'SIGNER'
                                        left join CompanyContacts bt3 (nolock) on cc3.userid = bt3.userid
                                        --inner join CaseAddress a on a.CaseId = cc.CaseId
                                        left join CaseCompanyAddressLink l on l.CaseId = cc.CaseId
                                        left join CompanyAddress ca on ca.CompanyAddressId = l.CompanyAddressId
                                        inner join CaseSubTypeRel r on r.CaseId = cc.CaseId
                                        inner join CaseSubTypes cst on cst.MetaDataId = r.MetaDataId
                                        left join ClientCase p on cc.ParentCaseId = p.CaseId
                                        left join CaseSubTypeRel pr on pr.CaseId = p.CaseId
                                        left join CaseSubTypes ps on ps.MetaDataId = pr.MetaDataId
                                        where CC.BALNumber = '" + bal_no + "' order by cc.BALNumber";
                        //20000.55.52,20000.50054.51
                        // Calling db object and sending the query and returning the DataTable
                        Database  db = new Database();
                        DataTable dt = db.SqlSelect(query);
                        // If Results found map data else send Error message
                        if (dt.Rows.Count > 0)
                        {
                            // Mapping DataTable to the 9035 and Lists object
                            MapDbData dbData = new MapDbData();
                            form     = dbData.MapdbResult(dt);
                            allLists = dbData.CreateLists(dt, bal_no);
                            dbData.AssignValue(form, allLists.parentCaseSubTypes);
                            Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message :  Data from SQL Query has been generated successfully.");
                        }
                        else
                        {
                            Log.Info("Bal Number : " + bal_no + ": Process : Draft9035 -  No Data Found from the SQL Query.");
                            TempData["Error"] = "You have entered an invalid case matter number. Please submit a new request with the correct matter number";
                            es.AddErrorESLog(ViewBag.id_no, "Business", "No Data Found from the SQL Query.", out errorMessage);
                            api.AddErrorQueueItem(ViewBag.id_no, TempData["Error"].ToString(), "Business", TempData["Error"].ToString(), "Failed", bal_no);
                            return(RedirectToAction("Error"));
                        }
                    }
                    // Second Asset check n if it is submit case (NOT IN USE)
                    //ViewBag.isSubmit = false;
                    //filter = "?$filter=Name eq '" + ViewBag.id_no + "'";
                    //AssetModel idModel = api.GetAsset(token, filter);
                    //if (idModel.value.Count > 0 && assetModel.value.Count > 0)
                    //{
                    //    foreach (var item in idModel.value)
                    //    {
                    //        if (item.Name == ViewBag.id_no)
                    //        {
                    //            ViewBag.isSubmit = true;
                    //        }
                    //    }
                    //}
                    //form.isSubmit = false;
                    obj.Form9035 = form;
                    obj.Lists    = allLists;
                    Log.Info("Bal Number : " + bal_no + " Process : Draft 9035 Page Loading, Message : Process has been executued successfully returning an object to View.");
                    return(View(obj));
                }
                else
                {
                    throw new Exception("HTTP Web Request Failed. The data in the URL is not found.");
                }
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly";
                Log.Error(ex, bal_no);
                es.AddErrorESLog(ViewBag.id_no, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(ViewBag.id_no, ex.Message, "Technical", ex.Message, "In Progress", bal_no);
                return(RedirectToAction("Error"));
            }
        }
示例#2
0
        public IHttpActionResult CreateAsset([FromBody] PostSaveData bodyModel)
        {
            string          assetResponse = "";
            string          logMsg        = "";
            Response        outResponse   = new Response();
            OrchestratorAPI api           = new OrchestratorAPI();
            string          errorMessage  = "";

            try
            {
                // Validate the input parameters
                if (string.IsNullOrEmpty(bodyModel.JsonString) && string.IsNullOrEmpty(bodyModel.Sysid) && string.IsNullOrEmpty(bodyModel.BalNumber))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : JsonString  parameter required";
                    Log.Info(logMsg);
                    assetResponse = JsonConvert.SerializeObject(outResponse);
                    es.AddErrorESLog(bodyModel.Sysid, "Technical", "Data Asset Parameter Missing", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Sysid, "Data Asset Parameter Missing", "Technical", "Data Asset Parameter Missing", "In Progress");
                    return(Json(assetResponse));
                }
                string filter = "";
                // configuration getting from Appsetting
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                // Saving all keys in a class object
                string token = api.Authentication(appKeys.isDevelopmentEnvironment);
                // check if token is generated or not
                if (string.IsNullOrEmpty(token))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : UIPATH Token has not been generated. Token : " + token;
                    Log.Info(logMsg);
                    es.AddErrorESLog(bodyModel.Sysid, "Technical", "UIPATH Token not generated. Authentication Failed.", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Sysid, "UIPATH Token not generated. Authentication Failed.", "Technical", "UIPATH Token not generated. Authentication Failed.", "In Progress");
                }
                else
                {
                    // GETS all the Assets against the BAL Number
                    string assetName = bodyModel.BalNumber;
                    filter = "?$filter=Name eq '" + bodyModel.BalNumber + "'";
                    AssetModel assetModel = api.GetAsset(token, filter);
                    // Removing List asset from the assetModel Object
                    if (assetModel.value.Count > 1)
                    {
                        foreach (var item in assetModel.value)
                        {
                            if (item.Name.Contains("Lists"))
                            {
                                assetModel.value.Remove(item);
                                break;
                            }
                        }
                    }
                    // create or update asset
                    Dictionary <string, object> assetBody = new Dictionary <string, object>();
                    assetBody.Add("Name", assetName);
                    assetBody.Add("ValueScope", "Global");
                    assetBody.Add("ValueType", "Text");
                    //Object to JSON
                    //string jsonString = JsonConvert.SerializeObject(bodyModel.JsonString);
                    //Compressing JSON
                    string compressValue = CompressString.Zip(bodyModel.JsonString);
                    //Encoding JSON
                    string encodeValue = SecureData.AesEncryptString(appKeys.SecretKey, compressValue);
                    int    chkStrLen   = encodeValue.Length;
                    // If length is greater than 4000 Create 2 Assets elsse 1
                    if (chkStrLen > 4000)
                    {
                        assetBody.Add("StringValue", encodeValue.Substring(0, 4000));
                        assetResponse = api.CreateAsset(assetModel, token, assetBody);
                        string secondAsset = encodeValue.Substring(4000);
                        // get n check if asset exist
                        string filter1 = "?$filter=Name eq '" + bodyModel.BalNumber + " A" + "'";
                        assetModel = api.GetAsset(token, filter1);
                        //second asset
                        Dictionary <string, object> asset2Body = new Dictionary <string, object>();
                        asset2Body.Add("ValueScope", "Global");
                        asset2Body.Add("ValueType", "Text");
                        asset2Body.Add("Name", bodyModel.BalNumber + " A");
                        asset2Body.Add("StringValue", secondAsset);
                        assetResponse = api.CreateAsset(assetModel, token, asset2Body);
                        logMsg        = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : 2 Assets has been created successfully";
                        Log.Info(logMsg);
                    }
                    else
                    {
                        // Delete the current existing assets first
                        if (assetModel.value.Count == 2)
                        {
                            string id          = assetModel.value[1].Id.ToString();
                            string deleteAsset = api.DeleteAsset(id, token);
                            logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Extra Asset has been deleted";
                            Log.Info(logMsg);
                        }
                        assetBody.Add("StringValue", encodeValue);
                        assetResponse = api.CreateAsset(assetModel, token, assetBody);
                        logMsg        = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Data asset has been created";
                        Log.Info(logMsg);
                    }
                    //Compressing JSON
                    compressValue = CompressString.Zip(bodyModel.ListJsonString);
                    //Encoding JSON
                    encodeValue = SecureData.AesEncryptString(appKeys.SecretKey, compressValue);
                    // getting lists assets
                    filter = "?$filter=Name eq '" + bodyModel.BalNumber + ".Lists'";
                    AssetModel ListAssetModel = api.GetAsset(token, filter);
                    // Adding or updating Lits Assets
                    Dictionary <string, object> assetListBody = new Dictionary <string, object>();
                    assetListBody.Add("Name", bodyModel.BalNumber + ".Lists");
                    assetListBody.Add("ValueScope", "Global");
                    assetListBody.Add("ValueType", "Text");
                    assetListBody.Add("StringValue", encodeValue);

                    assetResponse = api.CreateAsset(ListAssetModel, token, assetListBody);
                    // get n check if asset exist
                    logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : List Asset has been created";
                    Log.Info(logMsg);
                    assetModel = api.GetAsset(token, filter);
                    // In Case of submit sends the message
                    if (assetModel.value.Count > 0 && bodyModel.isSubmit == true)
                    {
                        logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Submit 9035 has been executed.";
                        outResponse.success = true;
                        outResponse.message = "Your 9035 will be drafted on the DOL ETA site and a copy will be uploaded to Cobalt.  You will receive a notification from ServiceNow when it is complete.  If you have any questions, contact #automationinfo.";
                    }
                    // in case of save Later
                    else if (assetModel.value.Count > 0 && bodyModel.isSubmit == false)
                    {
                        logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Save Later has been executed";
                        outResponse.success = true;
                        outResponse.message = @"Your progress has been saved.  To access your draft 9035 in the future, click on the ""Access My Draft 9035"" button in your ServiceNow ticket and you will be redirected to the form.";
                    }
                    // In case of any error
                    else
                    {
                        logMsg = "Bal Number" + bodyModel.BalNumber + " , Process : Save9035 Create Asset, Message : Some error occurred while returning an asset";
                        outResponse.success = false;
                        outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    }
                    Log.Info(logMsg);
                }
            }
            catch (Exception ex)
            {
                outResponse.success = false;
                outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                Log.Error(ex, bodyModel.BalNumber);
                es.AddErrorESLog(bodyModel.Sysid, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(bodyModel.Sysid, ex.Message, "Technical", ex.Message, "In Progress");
            }
            assetResponse = JsonConvert.SerializeObject(outResponse);
            return(Json(assetResponse));
        }
        // POST: api/AddCredentials
        // Create the Credential Asset on UIPATH Orchestrator
        public IHttpActionResult Post([FromBody] CredentialAsset bodyModel)
        {
            string          assetResponse = "";
            Response        outResponse   = new Response();
            OrchestratorAPI api           = new OrchestratorAPI();
            ElasticSearch   es            = new ElasticSearch();
            string          logMsg        = "";
            string          errorMessage  = "";

            try
            {
                // Check if the Input Parameters has all the values or not
                if (string.IsNullOrEmpty(bodyModel.Username) && string.IsNullOrEmpty(bodyModel.Password) && string.IsNullOrEmpty(bodyModel.Name) && string.IsNullOrEmpty(bodyModel.Email))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    assetResponse       = JsonConvert.SerializeObject(outResponse);
                    logMsg = "Bal Number : " + bodyModel.Name + ", Proecess : Create Credential Asset, Message : Parameter : Username : "******"Password : "******" Name : " + bodyModel.Name + " Email : " + bodyModel.Email + " : Parameter is required.";
                    Log.Info(logMsg);
                    es.AddErrorESLog(bodyModel.Name, "Technical", "Credential Asset Parameter Missing", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Name, "Credential Asset Parameter Missing", "Technical", "Credential Asset Parameter Missing", "In Progress");
                    return(Json(assetResponse));
                }
                string filter = "";
                //  Get the Config from AppSettings
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                // UIPATH TOKEN
                string token = api.Authentication(appKeys.isDevelopmentEnvironment);
                // Send error message if the token is null
                if (string.IsNullOrEmpty(token))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number : " + bodyModel.Name + ", Proecess : Create Credential Asset, Message : You are not been able to authenticated. Token : " + token;
                    Log.Info(logMsg);
                    es.AddErrorESLog(bodyModel.Name, "Technical", "UIPATH Token not generated. Authentication Failed.", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Name, "UIPATH Token not generated. Authentication Failed.", "Technical", "UIPATH Token not generated. Authentication Failed.", "In Progress");
                }
                else
                {
                    // get n check if asset exist
                    filter = "?$filter=Name eq '" + bodyModel.Name + "'";
                    AssetModel assetModel = api.GetAsset(token, filter);
                    // create or update asset
                    Dictionary <string, object> assetBody = new Dictionary <string, object>();
                    assetBody.Add("Name", bodyModel.Name);
                    assetBody.Add("ValueScope", "Global");
                    assetBody.Add("ValueType", "Credential");
                    assetBody.Add("StringValue", "no idea");
                    assetBody.Add("CredentialUsername", bodyModel.Username);
                    assetBody.Add("CredentialPassword", bodyModel.Password);
                    assetResponse = api.CreateAsset(assetModel, token, assetBody);
                    // get n check if asset exist
                    assetModel = api.GetAsset(token, filter);
                    if (assetModel.value.Count > 0)
                    {
                        // Gets user old records and sets the new updated key against it
                        string esKeyID = "";
                        // gets the KeyID
                        string[] esResults   = es.GetESKey(bodyModel.Email, appKeys.LookupKey, out errorMessage);
                        string   initalKeyID = "";
                        if (esResults != null)
                        {
                            initalKeyID = esResults[1];
                        }
                        // Set the SecretKey against the KeyID
                        es.SetESKey(initalKeyID, bodyModel.Email, bodyModel.SecretKey, appKeys.LookupKey, out errorMessage, out esKeyID);

                        outResponse.success = true;
                        outResponse.message = esKeyID;
                        logMsg = "Bal Number : " + bodyModel.Name + " Process : Create Credential Asset, Message :  The method has been successfully exexuted.";
                        Log.Info(logMsg);
                    }
                    else
                    {
                        outResponse.success = false;
                        outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                        logMsg = "Bal Number : " + bodyModel.Name + " Process : Create Credential Asset, Message :  The asset has not been found";
                        Log.Info(logMsg);
                        es.AddErrorESLog(bodyModel.Name, "Technical", "The Credential Asset has not been created", out errorMessage);
                        api.AddErrorQueueItem(bodyModel.Name, "The Credential Asset has not been created", "Technical", "The Credential Asset has not been created", "In Progress");
                    }
                }
            }
            catch (Exception ex)
            {
                outResponse.success = false;
                outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                Log.Error(ex, bodyModel.Name);
                es.AddErrorESLog(bodyModel.Name, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(bodyModel.Name, ex.Message, "Technical", ex.Message, "In Progress");
            }
            assetResponse = JsonConvert.SerializeObject(outResponse);
            return(Json(assetResponse));
        }
示例#4
0
        public IHttpActionResult AddQueueItem([FromBody] PostSaveData bodyModel)
        {
            string          assetResponse = "";
            Response        outResponse   = new Response();
            OrchestratorAPI api           = new OrchestratorAPI();
            string          logMsg        = "";
            string          errorMessage  = "";

            try
            {
                if (string.IsNullOrEmpty(bodyModel.Sysid) && string.IsNullOrEmpty(bodyModel.BalNumber) && string.IsNullOrEmpty(bodyModel.Email))
                {
                    outResponse.success = false;
                    outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                    logMsg = "Bal Number : " + bodyModel.BalNumber + ", Process : Add Queue Item, Message : JsonString  parameter required";
                    Log.Info(logMsg);
                    assetResponse = JsonConvert.SerializeObject(outResponse);
                    es.AddErrorESLog(bodyModel.Sysid, "Technical", "QueueItem API Parameter Missing", out errorMessage);
                    api.AddErrorQueueItem(bodyModel.Sysid, "QueueItem API Parameter Missing", "Technical", "QueueItem API Parameter Missing", "In Progress");
                    return(Json(assetResponse));
                }
                string filter = "?$filter=Name eq '" + bodyModel.BalNumber + "'";
                // configuration
                AppSettingsValues appKeys = GetAppSettings.GetAppSettingsValues();
                string            token   = api.Authentication(appKeys.isDevelopmentEnvironment);

                AssetModel assetModel = api.GetAsset(token, filter);
                if (assetModel.value.Count > 0)
                {
                    SpecificContent content = new SpecificContent();
                    content.ID          = bodyModel.Sysid;
                    content.Err_Message = null;
                    content.Err_Type    = null;
                    content.Note        = null;
                    content.Status      = null;
                    content.Data        = "[{'CaseNo':'" + bodyModel.BalNumber + "','Email':'" + bodyModel.Email + "','EsIdNo':'" + bodyModel.EsIdNo + "', 'ExtraAsset':''}]";
                    if (assetModel.value.Count > 2)
                    {
                        content.Data = "[{'CaseNo':'" + bodyModel.BalNumber + "','Email':'" + bodyModel.Email + "','EsIdNo':'" + bodyModel.EsIdNo + "', 'ExtraAsset':'" + bodyModel.BalNumber + " A" + "'}]";
                    }

                    ItemData itemData = new ItemData();
                    itemData.Name            = appKeys.QueueName;
                    itemData.Priority        = "Normal";
                    itemData.SpecificContent = content;

                    RootObject queueItemBody = new RootObject();
                    queueItemBody.itemData = itemData;

                    string strQueue = JsonConvert.SerializeObject(queueItemBody);
                    string message  = api.AddQueueItem(token, strQueue);
                    outResponse.success = true;
                    outResponse.message = "Your 9035 will be drafted on FLAG and a copy will be updated to Cobalt. You will receive a notification from ServiceNow when it is complete. if you have any questions, contact #automationinfo";
                    logMsg = "Bal Number : " + bodyModel.BalNumber + ", Process : Add Queue Item, Message : Queueitem has been added.";
                    Log.Info(logMsg);
                }
            }
            catch (Exception ex)
            {
                outResponse.success = false;
                outResponse.message = "Sorry, there seems to be an issue with your request.  Please send an email to #automationinfo with your ServiceNow ticket number and we will contact you shortly.";
                Log.Error(ex, bodyModel.BalNumber);
                es.AddErrorESLog(bodyModel.Sysid, "Technical", ex.Message, out errorMessage);
                api.AddErrorQueueItem(bodyModel.Sysid, ex.Message, "Technical", ex.Message, "In Progress");
            }
            assetResponse = JsonConvert.SerializeObject(outResponse);
            return(Json(assetResponse));
        }