/// <summary> /// /// </summary> public APIBaseController() { APIResponse = new ApiResponseWrapper(); APIResponse.apiResponseData = null; APIResponse.apiResponseMessage = "Invalid API Call from Client!!!"; APIResponse.apiResponseStatus = false; }
public async void SendTallyDayBookInformation(object param) { if (TallyConnectedStatus == enumTallyConnectedStatus.c) { ApiResponseWrapper <string> res = await GetTallyDayBookInformation("ITLION"); if (res.IsSuccessful) { TallyDayBookInformationStr = res.Data; TallyDayBookInfoResquestModel tallyDayBookInfoResquestModel = new TallyDayBookInfoResquestModel(enumXMLType.daybook, GlobalSettings.UserName, "ITLION", TallyDayBookInformationStr); ApiResponseWrapper <TallyDayBookInfoResponseModel> res1 = await ApiManager.getInstance().SendTallyDayBookInformation(tallyDayBookInfoResquestModel); if (!res1.IsSuccessful) { MessageBox.Show(res1.Message, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show(MessageConstants.SentTallyDayBookInformationSuccess, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } } } else { MessageBox.Show(MessageConstants.TallyNotConnected, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } }
public ApiResponseWrapper <TrainingResponse> SaveTrainingData(TrainingDetailsRequest request) { ApiResponseWrapper <TrainingResponse> response = new ApiResponseWrapper <TrainingResponse>(); Validation validation = ValidateData(request); if (validation.IsValidationFailed) { response.SetFailure(new TrainingResponse(), validation); } else { TrainingDetails newTrainingDetails = _mapper.Map <TrainingDetailsRequest, TrainingDetails>(request); int TrainingId = _TrainingAppModule.Save(newTrainingDetails); if (TrainingId > 0) { TrainingResponse responseData = new TrainingResponse() { TrainingId = TrainingId, TrainingDays = DateDifference(request) }; response.SetSuccess(responseData); } else { response.SetException(new TrainingResponse()); } } return(response); }
public async Task <ApiResponseWrapper <TallyConnectedCompaniesResponseModel> > SendTallyConnectedCompanies(TallyConnectedCompaniesResquestModel tallyConnectedCompaniesResquestModel) { ApiResponseWrapper <TallyConnectedCompaniesResponseModel> res = new ApiResponseWrapper <TallyConnectedCompaniesResponseModel>(); try { HttpClient client = new HttpClient(); //specify to use TLS 1.2 as default connection System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var values = new Dictionary <string, string> { { "login_id", tallyConnectedCompaniesResquestModel.UserName }, { "company_name", tallyConnectedCompaniesResquestModel.CompanyNames } }; var content = new FormUrlEncodedContent(values); var response = await client.PostAsync(ApiConstants.CompanyInsertApiUrl, content); string result = response.Content.ReadAsStringAsync().Result; response.Dispose(); res = new ApiResponseWrapper <TallyConnectedCompaniesResponseModel>(true, JsonConvert.DeserializeObject <TallyConnectedCompaniesResponseModel>(result)); } catch (Exception ex) { res = new ApiResponseWrapper <TallyConnectedCompaniesResponseModel>(false, null, ex.Message); } return(res); }
public static void VmAsserts(ApiResponseWrapper <List <SandboxResourceLight> > responseWrapper, bool vmDeleted, bool vmDeleteFinished, params string[] expectedVmNames) { ApiResponseBasicAsserts.ExpectSuccess <List <SandboxResourceLight> >(responseWrapper); var index = 0; foreach (var curResource in responseWrapper.Content) { if (index < 4) { continue; } Assert.NotNull(curResource.Name); IsRequiredType(index, curResource, expectedVmNames); if (!vmDeleted) { Assert.Contains(CloudResourceStatus.CREATING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } else if (vmDeleted && !vmDeleteFinished) { Assert.Contains(CloudResourceStatus.DELETING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } else if (vmDeleteFinished) { Assert.Contains(CloudResourceStatus.DELETING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } index++; } }
public IActionResult Calculate([FromBody] CalculateFormulaRequest calculateFormulaRequest) { try { var formulaEvaluatorResponse = calculateService.Calculate(calculateFormulaRequest); var apiResponseWrapper = new ApiResponseWrapper <FormulaResponse> { Data = new FormulaResponse { Value = formulaEvaluatorResponse.Value }, Message = formulaEvaluatorResponse.Message, ErrorCount = formulaEvaluatorResponse.IsSuccess ? 0 : 1, Errors = formulaEvaluatorResponse.IsSuccess ? new List <string>() : new List <string> { formulaEvaluatorResponse.Message } }; return(formulaEvaluatorResponse.IsSuccess ? Ok(apiResponseWrapper) : BadRequest(apiResponseWrapper)); } catch (Exception ex) { logger.LogError(ex, "{Message}", ex.Message); return(BadRequest(new ApiResponseWrapper <WebServiceResponse> { Message = ex.Message, Status = ApiConstants.FailedResult })); } }
public async void SendTallyConnectedCompaniesToServer(object param) { if (TallyConnectedStatus == enumTallyConnectedStatus.c) { ApiResponseWrapper <string> res = await GetTallyConnected(); if (res.IsSuccessful) { TallyConnectedCompanyStr = res.Data; TallyConnectedCompaniesResquestModel tallyConnectedCompaniesResquestModel = new TallyConnectedCompaniesResquestModel(GlobalSettings.UserName, TallyConnectedCompanyStr); ApiResponseWrapper <TallyConnectedCompaniesResponseModel> res1 = await ApiManager.getInstance().SendTallyConnectedCompanies(tallyConnectedCompaniesResquestModel); if (!res1.IsSuccessful) { MessageBox.Show(res1.Message, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show(MessageConstants.SentTallyConnectedCompanySuccess, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } } } else { MessageBox.Show(MessageConstants.TallyNotConnected, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static void SandboxResourceAsserts(ApiResponseWrapper <List <SandboxResourceLight> > responseWrapper, bool createFinished) { ApiResponseBasicAsserts.ExpectSuccess <List <SandboxResourceLight> >(responseWrapper); var index = 0; foreach (var curResource in responseWrapper.Content) { if (index > 4) { break; } Assert.NotNull(curResource.Name); IsRequiredType(index, curResource); if (createFinished) { Assert.Equal(CloudResourceStatus.OK, curResource.Status); } else { Assert.Contains(CloudResourceStatus.CREATING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); } index++; } }
public static void NewlyCreatedExpectSuccess(SandboxCreateDto createRequest, ApiResponseWrapper <SandboxDetails> responseWrapper) { ApiResponseBasicAsserts.ExpectSuccess <SandboxDetails>(responseWrapper); Assert.NotEqual <int>(0, responseWrapper.Content.Id); Assert.Equal(createRequest.Name, responseWrapper.Content.Name); Assert.Equal(createRequest.Region, responseWrapper.Content.Region); }
ApiResponseWrapper CreateResponseWrapper(HttpResponseMessage message) { var responseWrapper = new ApiResponseWrapper { StatusCode = message.StatusCode }; return(responseWrapper); }
public static void ExpectFailureWithMessage(ApiResponseWrapper <Common.Dto.ErrorResponse> responseWrapper, HttpStatusCode expectedStatusCode, string messageShouldContain = null) { Assert.Equal(expectedStatusCode, responseWrapper.StatusCode); if (!string.IsNullOrWhiteSpace(messageShouldContain)) { Assert.Contains(messageShouldContain, responseWrapper.Content.Message); } }
public static void ExpectSuccess(StudyCreateDto createRequest, ApiResponseWrapper <StudyDetailsDto> responseWrapper) { ApiResponseBasicAsserts.ExpectSuccess <StudyDetailsDto>(responseWrapper); Assert.NotEqual <int>(0, responseWrapper.Content.Id); Assert.Equal(createRequest.Name, responseWrapper.Content.Name); Assert.Equal(createRequest.Vendor, responseWrapper.Content.Vendor); Assert.Equal(createRequest.WbsCode, responseWrapper.Content.WbsCode); }
public static void ExpectSuccess(ApiResponseWrapper <SandboxResourceLight> responseWrapper, string statusShouldContain) { ApiResponseBasicAsserts.ExpectSuccess <SandboxResourceLight>(responseWrapper); var sandboxResourceResponse = responseWrapper.Content; Assert.NotNull(sandboxResourceResponse.Name); Assert.Null(sandboxResourceResponse.RetryLink); Assert.Contains(statusShouldContain, sandboxResourceResponse.Status); }
public async Task <ApiResponseWrapper> UpdateEntity(UserInfo entityObject) { InjectCommonParameters(true, entityObject); customCommand.CommandText = UserInfo.const_Proc_UserInfo_Update; customCommand.CommandType = CommandType.StoredProcedure; DatabaseEngine objDatabaseEngine = new DatabaseEngine(connectionString); ApiResponseWrapper objApiResponseWrapper = await objDatabaseEngine.ExecuteObjectAsync(customCommand, false); objDatabaseEngine.returnAPIResponse <UserInfo>(ref objApiResponseWrapper); return(objApiResponseWrapper); }
/// <summary> /// This method will generate Exception object to be thrown to user. /// </summary> /// <param name="errorMessage"></param> /// <param name="statusCode"></param> /// <returns></returns> private ApiResponseWrapper GenerateExceptionObject(string errorMessage, string statusCode, bool foreceLogout) { List <string> objEmptyResponse = new List <string>(); ApiResponseWrapper apiError = new ApiResponseWrapper(); apiError.apiResponseData = objEmptyResponse; apiError.apiResponseMessage = errorMessage; apiError.forceLogout = foreceLogout; apiError.apiResponseCode = statusCode; return(apiError); }
async Task <ApiResponseWrapper <T> > CreateResponseWrapper <T>(HttpResponseMessage message) { var responseWrapper = new ApiResponseWrapper <T> { StatusCode = message.StatusCode, ReasonPhrase = message.ReasonPhrase, Content = await GetResponseObject <T>(message) }; return(responseWrapper); }
public async Task <ApiResponseWrapper> DeleteEntity(UserInfo entityObject) { customCommand.Parameters.Clear(); customCommand.Parameters.AddWithValue(UserInfo.const_Field_Id, entityObject.Id); customCommand.CommandText = UserInfo.const_Proc_UserInfo_ChangeRecordStatus; customCommand.CommandType = CommandType.StoredProcedure; DatabaseEngine objDatabaseEngine = new DatabaseEngine(connectionString); ApiResponseWrapper objApiResponseWrapper = await objDatabaseEngine.ExecuteObjectAsync(customCommand, false); objDatabaseEngine.returnAPIResponse <UserInfo>(ref objApiResponseWrapper); return(objApiResponseWrapper); }
public void returnAPIResponse <T>(ref ApiResponseWrapper objApiResponseWrapper) { DataSet dsOutput = objApiResponseWrapper.apiResponseData; List <T> lstEntityToReturn = new List <T>(); if (dsOutput.Tables.Count > 0) { lstEntityToReturn = AutoMapper.ConvertDataTable <T>(dsOutput.Tables[0]); } objApiResponseWrapper.apiResponseStatus = objApiResponseWrapper.apiResponseMessage.ToLower().Contains(SystemLevelConstants.const_Result_Success); objApiResponseWrapper.apiResponseData = lstEntityToReturn; }
protected async Task <ApiResponseWrapper> ProcessWorkQueue(int timesToRun = 1) { ApiResponseWrapper apiResponseWrapper = null; for (var counter = 0; counter < timesToRun; counter++) { apiResponseWrapper = await _restHelper.Get("api/provisioningqueue/lookforwork"); Assert.Equal(System.Net.HttpStatusCode.OK, apiResponseWrapper.StatusCode); } return(apiResponseWrapper); }
public async Task <ApiResponseWrapper> ExecuteObjectAsync(SqlCommand customSqlCommand, bool isQuery) { apiDataResponse = new ApiResponseWrapper(); using (dbConnection = new SqlConnection(connectionString)) { customSqlCommand.CommandTimeout = 1200; if (dbConnection.State != ConnectionState.Open) { dbConnection.Open(); } customSqlCommand.Connection = dbConnection; List <SqlParameter> sqlpList = new List <SqlParameter>(); if (sqlpList.Count == 0) { sqlpList = AddApiLogInfoParameterList(); foreach (SqlParameter sqlp in sqlpList.ToList()) { if (customSqlCommand.Parameters.IndexOf(sqlp.ParameterName) == -1) { customSqlCommand.Parameters.Add(sqlp); } } } DataSet ds = new DataSet(); using (SqlDataAdapter da = new SqlDataAdapter(customSqlCommand)) { da.Fill(ds); apiDataResponse.apiResponseData = ds; } if (isQuery) { apiDataResponse.apiResponseMessage = SystemLevelConstants.const_Result_Success; apiDataResponse.apiResponseStatus = true; } else { string strMessage = customSqlCommand.Parameters[SystemLevelConstants.const_Field_EntityMessage].Value.ToString(); apiDataResponse.apiResponseStatus = strMessage.Contains(SystemLevelConstants.const_Result_Success); apiDataResponse.apiResponseMessage = strMessage; } } if (apiDataResponse.apiResponseData == null) { List <string> lsDefaultReturn = new List <string>(); apiDataResponse.apiResponseData = lsDefaultReturn; } return(apiDataResponse); }
public async void SendTallyStatusToServer(object param) { TallyConnectedResquestModel tallyConnectedResquestModel = new TallyConnectedResquestModel(GlobalSettings.UserName, enumTallyConnectedStatus.nc); ApiResponseWrapper <TallyConnectedResponseModel> res = await ApiManager.getInstance().SendTallyConnected(tallyConnectedResquestModel); if (!res.IsSuccessful) { MessageBox.Show(res.Message, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show(MessageConstants.SentTallyStatusSuccess, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } }
public void TrainingPost_MissingDataTest() { TrainingDetailsRequest request = new TrainingDetailsRequest() { StartDate = new DateTime(2019, 08, 10), EndDate = new DateTime(2019, 07, 10) }; ApiResponseWrapper <TrainingResponse> response = _controller.Post(request); Assert.IsNotNull(response); Assert.AreEqual(response.Status, Status.Failure); Assert.AreEqual(response.validation.IsValidationFailed, true); Assert.AreNotEqual(response.validation.ValidationMessage.Count, 0); }
public async void CheckTallyConnected(object param) { ApiResponseWrapper <string> res = await GetTallyConnected(); if (!res.IsSuccessful) { TallyConnectedStatus = enumTallyConnectedStatus.nc; MessageBox.Show(MessageConstants.TallyNotConnected, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show(MessageConstants.TallyConnected, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); TallyConnectedStatus = enumTallyConnectedStatus.c; } }
public static void AfterProvisioning(ApiResponseWrapper <List <VmDto> > responseWrapper, params string[] expectedVmNames) { ApiResponseBasicAsserts.ExpectSuccess <List <VmDto> >(responseWrapper); var sandboxResourceResponse = responseWrapper.Content; var index = 0; foreach (var curResource in sandboxResourceResponse) { Assert.NotNull(curResource.Name); Assert.Equal(CloudResourceStatus.OK, curResource.Status); index++; } }
public async void Login(object param) { //var words = new[] { ",this", " is ", "a", "test", "Super, \"luxurious\" truck" }; //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvAlwaysQuote<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvRfc4180<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvBare<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvTrimAlwaysQuote<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvTrimRfc4180<string>))); //System.Diagnostics.Debug.WriteLine(words.ToCsv(x => x, typeof(CsvTrimBare<string>))); //string str = "<ENVELOPE><COMPANYNAME.LIST><COMPANYNAME>Itlion</COMPANYNAME><COMPANYNAME>Itlion</COMPANYNAME><COMPANYNAME>Itlion</COMPANYNAME>" + // "<COMPANYNAME>Itlion</COMPANYNAME></COMPANYNAME.LIST></ENVELOPE>"; //ENVELOPE CompanyList = XmlHelper.Deserialize<ENVELOPE>(str); //System.Diagnostics.Debug.WriteLine(CompanyList.COMPANYNAME_LIST.COMPANYNAME.ToCsv(x => x, typeof(CsvTrimBare<string>))); if (this.UserNm == string.Empty || this.Password == string.Empty) { MessageBox.Show(MessageConstants.UserNamePasswordRequired, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } else { //bool resa= ApiManager.getInstance().CHECKCONNECTED(); GlobalSettings.UserName = this.UserNm; GlobalSettings.Password = this.Password; LoginResquestModel loginResquestModel = new LoginResquestModel(this.UserNm, this.Password); ApiResponseWrapper <LoginResposeModel> res = await ApiManager.getInstance().Login(loginResquestModel); if (res == null || res.IsSuccessful == false) { MessageBox.Show(MessageConstants.LoginFailureMessage("invalid credentials"), Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (res.Data.status) { if (param != null) { Window win = param as Window; //TempMainContainerView tempMainContainerView = new TempMainContainerView(); TempTestView tempMainContainerView = new TempTestView(); tempMainContainerView.Owner = win; win.Hide(); tempMainContainerView.ShowDialog(); } //MessageBox.Show(MessageConstants.LoginSuccess, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } } }
public async void CheckTallyDayBookInformation(object param) { if (TallyConnectedStatus == enumTallyConnectedStatus.c) { ApiResponseWrapper <string> res = await GetTallyDayBookInformation("ITLION"); if (res.IsSuccessful) { TallyDayBookInformationStr = res.Data; } } else { MessageBox.Show(MessageConstants.TallyNotConnected, Application.Current.Resources["AppTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Warning); } }
/// <summary> /// This method will be called upon occurrence of Exception on any of method of any controller. /// </summary> /// <param name="context"></param> public override void OnException(ExceptionContext context) { StringBuilder sbErrorInfo = new StringBuilder(); ApiResponseWrapper apiError = new ApiResponseWrapper(); string errorInControllerValue = string.Empty; string actionMethodValue = string.Empty; foreach (KeyValuePair <string, string> kva in context.ActionDescriptor.RouteValues) { if (kva.Key.ToLower() == "controller") { errorInControllerValue = kva.Value; } if (kva.Key.ToLower() == "action") { actionMethodValue = kva.Value; } } sbErrorInfo.AppendLine("Error Route: [Controller] : " + errorInControllerValue + " | [Action] : " + actionMethodValue); sbErrorInfo.AppendLine("Error Message : " + context.Exception.Message); sbErrorInfo.AppendLine("Stack Trace: " + context.Exception.StackTrace); string errorDetails = sbErrorInfo.ToString(); if (context.Exception is UnauthorizedAccessException) { apiError = GenerateExceptionObject(errorDetails, SystemEnums.ResponseCodes.UnAuthorized.ToString(), true); context.HttpContext.Response.StatusCode = Convert.ToInt32(SystemEnums.ResponseCodes.UnAuthorized); } else { apiError = GenerateExceptionObject(errorDetails, SystemEnums.ResponseCodes.InternalServerError.ToString(), false); context.HttpContext.Response.StatusCode = Convert.ToInt32(SystemEnums.ResponseCodes.InternalServerError); } context.ExceptionHandled = true; if (context.HttpContext.Request.Headers.TryGetValue("LoggedInUserId", out var vUID)) { errorDetails = "Logged In User (UID) : " + vUID + Environment.NewLine + errorDetails; } // always return a JSON result context.Result = new JsonResult(apiError); base.OnException(context); }
public static void BeforeProvisioning(ApiResponseWrapper <List <VmDto> > responseWrapper, params string[] expectedVmNames) { ApiResponseBasicAsserts.ExpectSuccess <List <VmDto> >(responseWrapper); var sandboxVmResponse = responseWrapper.Content; var index = 0; foreach (var curResource in sandboxVmResponse) { Assert.NotNull(curResource.Name); Assert.Contains(CloudResourceStatus.CREATING, curResource.Status); Assert.Contains(CloudResourceStatus.IN_QUEUE, curResource.Status); index++; } }
public void TrainingPost_PositiveTest() { TrainingDetailsRequest request = new TrainingDetailsRequest() { TrainingName = "Training 1", StartDate = new DateTime(2019, 06, 10), EndDate = new DateTime(2019, 07, 10) }; ApiResponseWrapper <TrainingResponse> response = _controller.Post(request); Assert.IsNotNull(response); Assert.IsNotNull(response.Data); Assert.AreEqual(response.Status, Status.Success); Assert.AreNotEqual(response.Data.TrainingId, 0); Assert.AreNotEqual(response.Data.TrainingDays, 0); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="next"></param> /// <returns></returns> public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (context.ModelState.IsValid == false) { var errorInModelState = context.ModelState .Where(x => x.Value.Errors.Count > 0) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Errors.Select(x => x.ErrorMessage)).ToArray(); ApiResponseWrapper objApiResponseWrapper = new ApiResponseWrapper(); foreach (var error in errorInModelState) { foreach (var subError in error.Value) { objApiResponseWrapper.apiResponseMessage = objApiResponseWrapper.apiResponseMessage + error.Key + " : " + subError + Environment.NewLine; } } objApiResponseWrapper.apiResponseStatus = false; objApiResponseWrapper.apiResponseCode = "400"; objApiResponseWrapper.forceLogout = true; List <String> objEmptyResponse = new List <string>(); objApiResponseWrapper.apiResponseData = objEmptyResponse; //context.Result = new BadRequestObjectResult(objApiResponseWrapper.apiResponseMessage); //var responseObj = new //{ // Message = "Bad Request", // Errors = objApiResponseWrapper.apiResponseMessage //}; context.Result = new JsonResult(objApiResponseWrapper) { StatusCode = 400 }; return; } await next(); }