Exemplo n.º 1
0
        public bool ModifyDepartment(Hashtable hTable)
        {
            clsGlobalVariable.strExceptionReport = string.Empty;
            string     statusCode   = string.Empty;
            string     result       = string.Empty;
            string     RegionResult = string.Empty;
            clsGeneric oGeneric     = new clsGeneric();
            string     URI          = string.Empty;
            string     strGroupID   = string.Empty;

            List <string> lCourseId = new List <string>();
            bool          _Flag     = false;
            string        _UserID   = string.Empty;

            try
            {
                clsPage      oPage   = new clsPage(iWebdriver);
                clsRegionApi oRegion = new clsRegionApi();
                _orgID       = oPage.GetOrganizationID();
                clsAPI.orgID = _orgID;
                //  oRegion.name = hTable["Name"].ToString();

                GetAPICredentials oGetAPICredentials = new GetAPICredentials();

                oGeneric.GetApiResponseCodeData(out statusCode, out result, "GET", ApplicationSettings.APIURI() + clsAPI.orgCredential.Replace("$", _orgID), oGetAPICredentials, "H2", "", "");

                var        orgCredential = JsonConvert.DeserializeObject <GetAPICredentials>(result);
                Crypto3DES _des          = new Crypto3DES(ApplicationSettings.EComModuleEncKey());

                _ecomTransactionKey = _des.Decrypt3DES(orgCredential.TransactionKey);
                _ecomLoginKey       = _des.Decrypt3DES(orgCredential.LoginID);

                //Get All Regions Data of above organization
                oGeneric.GetApiResponseCodeData(out statusCode, out result, "GET", ApplicationSettings.APIURI() + clsAPI.Region.Replace("{orgid}", _orgID), oRegion, "H1", _ecomLoginKey, _ecomTransactionKey);

                //Convert the JSON data in List and put in a Local variable
                var RegionData = JsonConvert.DeserializeObject <List <GetRegion> >(result);

                //Find for my region and get its id and put in a variable

                string RegID = "";
                for (int iRegions = 0; iRegions < RegionData.Count; iRegions++)
                {
                    if (RegionData[iRegions].Name.Contains(hTable["RegionName"].ToString()))
                    {
                        RegID = RegionData[iRegions].ID.ToString();
                        break;
                    }
                    else
                    {
                        _Flag = false;
                    }
                }

                //Get All Divisions of a Region
                oGeneric.GetApiResponseCodeData(out statusCode, out result, "GET", clsAPI.apiURI + clsAPI.updateRegion.Replace("{orgid}", _orgID).Replace("{regionID}", RegID) + "/divisions", oRegion, "H1", _ecomLoginKey, _ecomTransactionKey);


                var DivisionData = JsonConvert.DeserializeObject <List <GetRegion> >(result);

                //Find for my division and get its id and put in a variable

                string DivID = "";
                for (int iDivs = 0; iDivs < DivisionData.Count; iDivs++)
                {
                    if (DivisionData[iDivs].Name.Contains(hTable["DivisionName"].ToString()))
                    {
                        DivID = DivisionData[iDivs].ID.ToString();
                        break;
                    }
                    else
                    {
                        _Flag = false;
                    }
                }

                //Get All Depts of a Reg and Division
                oGeneric.GetApiResponseCodeData(out statusCode, out result, "GET", clsAPI.apiURI + clsAPI.GetAllDepartments.Replace("{orgid}", _orgID).Replace("{regionID}", RegID).Replace("{divisionID}", DivID), oRegion, "H1", _ecomLoginKey, _ecomTransactionKey);

                var DeptData = JsonConvert.DeserializeObject <List <GetRegion> >(result);

                //Find for my dept and get its id and put in a variable

                string DeptID = "";
                for (int iDepts = 0; iDepts < DeptData.Count; iDepts++)
                {
                    if (DeptData[iDepts].Name.Contains(hTable["OldDeptName"].ToString()))
                    {
                        DeptID = DeptData[iDepts].ID.ToString();
                        break;
                    }
                    else
                    {
                        _Flag = false;
                    }
                }

                Thread.Sleep(clsGlobalVariable.iWaitMedium);

                if (hTable["TestCaseType"].ToString().ToUpper() == "POSITIVE")
                {
                    clsDepartmentApi DepartmentData = new clsDepartmentApi();

                    DepartmentData.Name = hTable["NewDeptName"].ToString();

                    oGeneric.GetApiResponseCodeData(out statusCode, out result, "PUT", clsAPI.apiURI + clsAPI.GetSingleDepartment.Replace("{orgid}", _orgID).Replace("{regionID}", RegID).Replace("{divisionID}", DivID).Replace("{deptID}", DeptID), DepartmentData, "H1", _ecomLoginKey, _ecomTransactionKey);
                    if (statusCode == "NoContent/204")
                    {
                        _Flag = true;
                    }
                    else
                    {
                        _Flag = false;
                    }
                }
            }
            catch (Exception e)
            {
                clsException.ExceptionHandler(e, iWebdriver, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name);

                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool AddRegion(Hashtable hTable)
        {
            clsGlobalVariable.strExceptionReport = string.Empty;
            string     statusCode  = string.Empty;
            string     result      = string.Empty;
            string     GroupResult = string.Empty;
            clsGeneric oGeneric    = new clsGeneric();
            string     URI         = string.Empty;
            string     strGroupID  = string.Empty;

            List <string> lCourseId = new List <string>();
            bool          _Flag     = false;
            string        _UserID   = string.Empty;

            try
            {
                clsPage      oPage   = new clsPage(iWebdriver);
                clsRegionApi oRegion = new clsRegionApi();
                _orgID       = oPage.GetOrganizationID();
                clsAPI.orgID = _orgID;
                oRegion.name = hTable["Name"].ToString();

                GetAPICredentials oGetAPICredentials = new GetAPICredentials();

                oGeneric.GetApiResponseCodeData(out statusCode, out result, "GET", ApplicationSettings.APIURI() + clsAPI.orgCredential.Replace("$", _orgID), oGetAPICredentials, "H2", "", "");

                var        orgCredential = JsonConvert.DeserializeObject <GetAPICredentials>(result);
                Crypto3DES _des          = new Crypto3DES(ApplicationSettings.EComModuleEncKey());

                _ecomTransactionKey = _des.Decrypt3DES(orgCredential.TransactionKey);
                _ecomLoginKey       = _des.Decrypt3DES(orgCredential.LoginID);


                oGeneric.GetApiResponseCodeData(out statusCode, out result, "POST", ApplicationSettings.APIURI() + clsAPI.Region.Replace("{orgid}", _orgID), oRegion, "H1", _ecomLoginKey, _ecomTransactionKey);


                Thread.Sleep(clsGlobalVariable.iWaitMedium);

                if (hTable["TestCaseType"].ToString().ToUpper() == "POSITIVE")
                {
                    oGeneric.GetApiResponseCodeData(out statusCode, out result, "GET", ApplicationSettings.APIURI() + clsAPI.Region.Replace("{orgid}", _orgID), oRegion, "H1", _ecomLoginKey, _ecomTransactionKey);

                    var RegionData = JsonConvert.DeserializeObject <List <GetRegion> >(result);

                    _Flag = RegionData.Any(cus => cus.Name == hTable["Name"].ToString());

                    return(_Flag);
                }
                else
                {
                    if (result.Contains("ErrorCode") || result.Contains("Invalid URI."))
                    {
                        if (result.Contains("Invalid URI."))
                        {
                            return(true);
                        }


                        SuperAdminCoursePushDownErrorCode oError = new SuperAdminCoursePushDownErrorCode();
                        var error = JsonConvert.DeserializeObject <List <SuperAdminCoursePushDownError> >(result);

                        foreach (string errorcode in oError.coursePushDownErrorCode)
                        {
                            for (int i = 0; i < error.Count; i++)
                            {
                                if (error[i].ErrorCode == errorcode)
                                {
                                    _Flag = true;
                                }
                                else
                                {
                                    _Flag = false;
                                }
                            }
                            if (_Flag == true)
                            {
                                break;
                            }
                        }
                        return(_Flag);
                    }
                }
            }
            catch (Exception e)
            {
                clsException.ExceptionHandler(e, iWebdriver, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name);

                return(false);
            }

            return(_Flag);
        }