public async Task <IActionResult> GetSearchPrimaryKeys(LidTypeEnum lidType, string lid) { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Dashboard Info GetSearchPrimaryKeys ", "DashboardInfoController.cs", "GetSearchPrimaryKeys"), CancellationToken.None); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IActionResult response = null; try { //since no data in cache, now get data from DB var data = await _dashboardInfo.GetDashboardSearchPrimaryKeys(lidType, lid, null); response = Ok(data); } catch (Exception ex) { var msg = this._localizer?[DashboardInfoErrorKeys.GetPkErrors.ToString()]?.Value; await _loggingFacade.LogExceptionAsync(ex, this.HttpContext?.Request?.Headers["UserName"], LogLevels.Error, "Error in GetSearchPrimaryKeys()", CancellationToken.None); response = this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg); } await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Dashboard Info GetSearchPrimaryKeys Successful ", "DashboardInfoController.cs", "GetSearchPrimaryKeys"), CancellationToken.None); return(response); }
//Would be revisiting to modify the actual way of call method. public void CaseHistoryControllerTest_Success() { // Arrange LidTypeEnum LIDType = LidTypeEnum.CustomerNbr; string LID = ""; PaginationCaseHistory page = new PaginationCaseHistory(); string ExtraId = null; int lid = 648988; int CaseID = 8715123; MockCaseHistoryRepository mockCaseHistoryRepository = new MockCaseHistoryRepository(); ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> > expectedResult = mockCaseHistoryRepository.GetMockData(lid); IOptions <DataContext> optionsAccessor = Substitute.For <IOptions <DataContext> >(); IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>(); ICaseHistoryRepository mockRepo = Substitute.For <ICaseHistoryRepository>(); mockRepo.GetCaseHistoryInfo(LIDType, LID, ExtraId, page).ReturnsForAnyArgs(expectedResult.Result); // Act var caseHistory = mockRepo.GetCaseHistoryInfo(LIDType, "648988", ExtraId, page).Result; var actualRecord = (IList <Wp.CIS.LynkSystems.Model.CaseHistory>)caseHistory.ReturnedRecords; string caseInfo = actualRecord.Where(x => x.caseId == CaseID).FirstOrDefault().caseLevel; //// Assert Assert.Equal(((IList <Wp.CIS.LynkSystems.Model.CaseHistory>)actualRecord).Count, 6); Assert.Equal(caseInfo, "Customer"); }
/// <summary> /// This returns the primary key information. /// </summary> /// <param name="lidType"></param> /// <param name="lid"></param> /// <param name="lidPk"></param> /// <returns></returns> public async Task <DashboardPrimaryKeysModel> GetDashboardSearchPrimaryKeys(LidTypeEnum lidType, string lid, int?lidPk) { const string OutTerminalNbrParamName = "OutTerminalNbr"; const string OutMerchantIDParamName = "OutMerchantID"; const string OutCustIDParamName = "OutCustID"; const string OutputLidPkTypeParamName = "OutputLidPkType"; var response = await this._connectionFactory.GetConnection(async c => { var primaryKeyInfo = new DashboardPrimaryKeysModel(); var p = new DynamicParameters(); p.Add("InputLid", lid, DbType.String); p.Add("InputPk", lidPk, DbType.Int32); p.Add("InputType", (int)lidType, DbType.Int32); p.Add(OutTerminalNbrParamName, DbType.Int32, direction: ParameterDirection.Output); p.Add(OutMerchantIDParamName, DbType.Int32, direction: ParameterDirection.Output); p.Add(OutCustIDParamName, DbType.Int32, direction: ParameterDirection.Output); p.Add(OutputLidPkTypeParamName, DbType.Int32, direction: ParameterDirection.Output); //await c.QueryAsync<Wp.CIS.LynkSystems.Model.TransactionsInquiry>(sql: "[CISPlus].[uspCISPlusGetPrimaryKeys]", param: p, commandType: CommandType.StoredProcedure); await c.ExecuteAsync(sql: "[CISPlus].[uspCISPlusGetPrimaryKeys]", param: p, commandType: CommandType.StoredProcedure); primaryKeyInfo.TerminalNbr = p.Get <int?>(OutTerminalNbrParamName); primaryKeyInfo.MerchantID = p.Get <int?>(OutMerchantIDParamName); primaryKeyInfo.CustomerID = p.Get <int?>(OutCustIDParamName); primaryKeyInfo.LidType = (LidTypeEnum)p.Get <int?>(OutputLidPkTypeParamName); return(primaryKeyInfo); }); return(response); }
public async Task ContactListApiTest_Exception() { // Arrange LidTypeEnum LIDType = LidTypeEnum.CustomerNbr; string LID = ""; PaginationDemographics page = new PaginationDemographics(); string ssn = "3425"; MockContactListRepository mockContactListRepository = new MockContactListRepository(); ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn); ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>(); IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >(); IContactListRepository mockRepo = Substitute.For <IContactListRepository>(); IContactListApi contactListApi = Substitute.For <IContactListApi>(); IDistributedCache mockCache = Substitute.For <IDistributedCache>(); loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase(); mockRepo.GetContactListAsync(LIDType, LID, page).Throws(new Exception()); contactListApi = new ContactListApi(optionsAccessor, mockRepo, loggingFacade); //Assert await Assert.ThrowsAsync <Exception>(() => contactListApi.GetContactListAsync(LIDType, LID, page)); }
public async Task CaseHistoryApiTest_Exception() { // Arrange LidTypeEnum LIDType = LidTypeEnum.CustomerNbr; string LID = ""; PaginationCaseHistory page = new PaginationCaseHistory(); int lid = 648988; string ExtraId = null; MockCaseHistoryRepository mockCaseHistoryRepository = new MockCaseHistoryRepository(); ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> > expectedResult = mockCaseHistoryRepository.GetMockData(lid); IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >(); ICaseHistoryRepository mockRepo = Substitute.For <ICaseHistoryRepository>(); ICaseHistoryApi casehistoryApi = Substitute.For <ICaseHistoryApi>(); IDistributedCache mockCache = Substitute.For <IDistributedCache>(); mockRepo.GetCaseHistoryInfo(LIDType, LID, ExtraId, page).Throws(new Exception()); casehistoryApi = new CaseHistoryApi(optionsAccessor, mockRepo); //Assert await Assert.ThrowsAsync <Exception>(() => casehistoryApi.GetCaseHistory(LIDType, LID, ExtraId, page)); }
//Would be revisiting to modify the actual way of call method. public void ContactListRepositoryTest_Success() { // Arrange LidTypeEnum LIDType = LidTypeEnum.CustomerNbr; string LID = ""; PaginationDemographics page = new PaginationDemographics(); int NameAddressID = 3301636; string ssn = "3425"; MockContactListRepository mockContactListRepository = new MockContactListRepository(); ApiResult <GenericPaginationResponse <Demographics> > expectedResult = mockContactListRepository.GetMockData(ssn); IOptions <DataContext> optionsAccessor = Substitute.For <IOptions <DataContext> >(); IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>(); IContactListRepository mockRepo = Substitute.For <IContactListRepository>(); ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>(); loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase(); mockRepo.GetContactListAsync(LIDType, LID, page).ReturnsForAnyArgs(expectedResult.Result); // Act var contactList = mockRepo.GetContactListAsync(LIDType, LID, page).Result; var actualRecord = (IList <Wp.CIS.LynkSystems.Model.Demographics>)contactList.ReturnedRecords; string contactInfo = actualRecord.Where(x => x.NameAddressID == NameAddressID).FirstOrDefault().Name; //// Assert Assert.Equal(((IList <Demographics>)actualRecord).Count, 3); Assert.Equal(contactInfo, "Golden Corral Corporation"); }
/// <summary> /// /// </summary> /// <param name="lidtype"></param> /// <param name="lid"></param> /// <param name="lidPk"></param> /// <returns></returns> public async Task <DashboardPrimaryKeysModel> GetDashboardSearchPrimaryKeys(LidTypeEnum lidtype, string lid, int?lidPk) { DashboardPrimaryKeysModel response = null; try { response = await this._dashboardRepository .GetDashboardSearchPrimaryKeys(lidtype, lid, lidPk); switch (response.LidType) { case LidTypeEnum.Customer: if (true == response.CustomerID.HasValue) { response.RecordFound = true; response.ConvertedLidPk = response.CustomerID; } else { response.RecordFound = false; } break; case LidTypeEnum.Merchant: if (true == response.MerchantID.HasValue) { response.RecordFound = true; response.ConvertedLidPk = response.MerchantID; } else { response.RecordFound = false; } break; case LidTypeEnum.Terminal: if (true == response.TerminalNbr.HasValue) { response.RecordFound = true; response.ConvertedLidPk = response.TerminalNbr; } else { response.RecordFound = false; } break; default: response.RecordFound = false; break; } } catch (Exception) { throw; } return(response); }
public async Task <IEnumerable <AuditHistoryModel> > GetAuditHistoryAsync(LidTypeEnum lidType, int lid, ActionTypeEnum actionType) { var response = await this._connectionFactory.GetConnection(async c => { IEnumerable <AuditHistoryModel> auditRecords = null; var p = new DynamicParameters(); p.Add("LidType", (int)lidType, DbType.Int32); p.Add("Lid", (int)lid, DbType.Int32); p.Add("ActionType", (int)actionType, DbType.Int32); auditRecords = await c.QueryAsync <AuditHistoryModel>(sql: "uspGetAuditHistory", param: p, commandType: CommandType.StoredProcedure); return(auditRecords); }); return(response); }
public async Task <IActionResult> Get([FromQuery] LidTypeEnum lidType, [FromQuery] int lid, [FromQuery] ActionTypeEnum actionType) { IActionResult response = null; try { var auditHistory = await this._auditHistoryApi .GetLatestAuditHistoryRecordAsync(lidType, lid, actionType); response = this.Ok(auditHistory); } catch (Exception) { var msg = this._localizer?["AuditHistoryError"]?.Value; return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg)); } return(response); }
public async Task <IActionResult> Get([FromBody] CaseHistoryInput pageinput) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { LidTypeEnum LIDType = pageinput.lidTypeEnum; string LID = pageinput.LIDValue; string ExtraId = pageinput.ExtraID; PaginationCaseHistory page = pageinput.Page; var key = _localizer["UniqueKey"] + "_" + LID; if (page.SkipRecordNumber > 0) { key = key + "_" + page.SkipRecordNumber; } var result = (await _caseHistory.GetCaseHistory(LIDType, LID, ExtraId, page)); if (result.Result != null && result.Result.TotalNumberOfRecords > 0) { await _operation.AddCacheAsync(key, result.Result); return(Ok(result.Result)); } else { var msg = this._localizer["NoDataFound"]?.Value; result.Result.ModelMessage = msg; return(Ok(result.Result)); } } catch (Exception ex) { var msg = this._localizer?["InternalServerError"]?.Value; await _loggingFacade.LogExceptionAsync(ex, this.HttpContext?.Request?.Headers["UserName"], LogLevels.Error, "Error in CaseHistoryGet()", CancellationToken.None); return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg)); } }
//public AuditHistoryApi() //{ // var i = 0; // i++; //} #endregion #region IAuditHistoryApi Implementation /// <summary> /// This retrieves the most recent audit history record. /// </summary> /// <param name="lidType"></param> /// <param name="lid"></param> /// <param name="actionType"></param> /// <returns></returns> public async Task <AuditHistoryModel> GetLatestAuditHistoryRecordAsync(LidTypeEnum lidType, int lid, ActionTypeEnum actionType) { AuditHistoryModel response = null; var auditRecords = await this._auditHistoryRepository .GetAuditHistoryAsync(lidType, lid, actionType); if (null != auditRecords) { var auditList = new List <AuditHistoryModel>(auditRecords); if (auditList.Count > 0) { auditList = auditList .OrderByDescending(currentItem => currentItem.ActionDate) .ToList(); response = auditList[0]; } } return(response); }
/// <summary> /// Model - Merchant /// </summary> /// <param name="custId"></param> /// <returns></returns> public async Task <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.Demographics> > GetContactListAsync(LidTypeEnum LIDType, string LID, PaginationDemographics page) { try { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Contact List Repository GetContactListAsync for " + LIDType.ToString() + " Value - " + LID, "ContactListRepository.cs", "GetContactListAsync"), CancellationToken.None); var response = new GenericPaginationResponse <Demographics> { SkipRecords = page.SkipRecordNumber, PageSize = page.PageSize }; return(await this._connectionFactory.GetConnection(async c => { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Open Dapper Connection of SQL server for Contact List Repository for " + LIDType.ToString() + " Value - " + LID, "ContactListRepository.cs", "GetContactListAsync"), CancellationToken.None); var p = new DynamicParameters(); p.Add("iLIDType", LIDType, DbType.Int32); p.Add("iLID", LID, DbType.String); if (page.SortField != null) { p.Add("SortField", page.SortField, DbType.String); p.Add("@SortByAsc", page.SortFieldByAsc, DbType.Boolean); } if (page.FilterContact != null) { p.Add("FilterByValueForContact", page.FilterContact, DbType.String); } if (page.FilterLast4 != null) { p.Add("FilterByValueForSSN", page.FilterLast4, DbType.String); } if (page.FilterRole != null) { p.Add("FilterByValueForTitle", page.FilterRole, DbType.String); } if (page.PageSize != 0) { p.Add("PageSize", page.PageSize, DbType.Int16); } if (page.SkipRecordNumber != 0) { p.Add("SkipRecordNumber", page.SkipRecordNumber, DbType.Int16); } p.Add("MaximumRecsLimit", maxRecordCount, DbType.Int16); p.Add("TotalRecordsCount", DbType.Int32, direction: ParameterDirection.Output); await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Dapper Connection parameterized Query for Contact List Repository for " + LIDType.ToString() + " Value - " + LID, "ContactListRepository.cs", "GetContactListAsync"), CancellationToken.None); response.ReturnedRecords = await c.QueryAsync <Wp.CIS.LynkSystems.Model.Demographics>(sql: "[CISPlus].[uspCISPlusGetDemographicsByLIdType]", param: p, commandType: CommandType.StoredProcedure); response.TotalNumberOfRecords = p.Get <int>("TotalRecordsCount"); await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Successful DB call for Contact List Repository Query result for " + LIDType.ToString() + " Value - " + LID, "ContactListRepository.cs", "GetContactListAsync"), CancellationToken.None); return response; })); } catch (Exception ex) { var msg = String.Format("{0}.GetContactListAsync() experienced an exception (not a timeout)", GetType().FullName); await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, "Error Occurred for " + LIDType.ToString() + " Value - " + LID + " " + msg + ex.ToString() + ex.Message, "ContactListRepository.cs", "GetContactListAsync"), CancellationToken.None); throw; } }
public async Task <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory> > GetCaseHistoryInfo(LidTypeEnum lidtype, string lid, string extraId, PaginationCaseHistory page) { try { var response = new GenericPaginationResponse <Wp.CIS.LynkSystems.Model.CaseHistory>(); return(await this._connectionFactory.GetConnection(async c => { var p = new DynamicParameters(); p.Add("LIDType", lidtype, DbType.Int32); p.Add("LID", lid, DbType.String); p.Add("MaximumRecsLimit", maxrecordslimit, DbType.String); if (extraId != null) { p.Add("ExtraID", extraId, DbType.String); } p.Add("PageSize", page.PageSize, DbType.Int32); p.Add("SkipRecords", page.SkipRecordNumber, DbType.Int32); if (page.SortField != null) { p.Add("SortField", page.SortField, DbType.String); } p.Add("SortOrder", page.SortFieldByAsc, DbType.Boolean); if (page.FilterCaseId != null) { p.Add("FilterCaseId", page.FilterCaseId, DbType.String); } if (page.FilterCaseDesc != null) { p.Add("FilterCaseDesc", page.FilterCaseDesc, DbType.String); } if (page.FilterOrgDeptName != null) { p.Add("FilterOrgDeptName", page.FilterOrgDeptName, DbType.String); } if (page.FilterCaseLevel != null) { p.Add("FilterCaseLevel", page.FilterCaseLevel, DbType.String); } if (true == page.FilterCreateDate.HasValue) { var beginCreateDate = new DateTime(page.FilterCreateDate.Value.Year, page.FilterCreateDate.Value.Month, page.FilterCreateDate.Value.Day); var endCreateDate = new DateTime(page.FilterCreateDate.Value.Year, page.FilterCreateDate.Value.Month, page.FilterCreateDate.Value.Day, 23, 59, 59); p.Add("FilterBeginCreateDate", beginCreateDate, DbType.Date); p.Add("FilterEndCreateDate", endCreateDate, DbType.Date); } p.Add("TotalRecords", DbType.Int32, direction: ParameterDirection.Output); response.ReturnedRecords = await c.QueryAsync <Wp.CIS.LynkSystems.Model.CaseHistory>(sql: "CISPlus.uspCISPlusGetCaseHistoryRecords", param: p, commandType: CommandType.StoredProcedure); response.TotalNumberOfRecords = p.Get <int>("TotalRecords"); return response; })); } catch (System.Exception) { throw; } }
public async Task <ApiResult <GenericPaginationResponse <CaseHistory> > > GetCaseHistory(LidTypeEnum lidtype, string lid, string extraId, PaginationCaseHistory page) { ApiResult <GenericPaginationResponse <CaseHistory> > response = new ApiResult <GenericPaginationResponse <CaseHistory> >(); try { response.Result = await _casehistoryrepository.GetCaseHistoryInfo(lidtype, lid, extraId, page); } catch (Exception) { throw; } return(response); }
public async Task <IActionResult> GetContactList([FromBody] ContactListInput pageinput) { try { LidTypeEnum LIDType = pageinput.lidTypeEnum; string LID = pageinput.LIDValue; await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "start calling the HttpPost method for the Contact List controller for input - " + LIDType + ", Value - " + LID, "ContactListController.cs", "GetContactList"), CancellationToken.None); PaginationDemographics page = pageinput.Page; var key = UniqueCachingKey(pageinput); if (!ModelState.IsValid) { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, ModelState.ToString(), "ContactListController.cs", "GetContactList"), CancellationToken.None); return(BadRequest(ModelState)); } var data = _operation.RetrieveCache(key, new GenericPaginationResponse <Demographics>()); if (data == null) { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "calling service for getting Contact List resultset from DB", "ContactListController.cs", "GetContactList"), CancellationToken.None); //since no data in cache, now get data from DB var result = await _contactList.GetContactListAsync(LIDType, LID, page); if (result.ErrorMessages.Count == 0) { if (result.Result != null && result.Result.TotalNumberOfRecords > 0) { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, " Fetched the Contact List resultset", "ContactListController.cs", "GetContactList"), CancellationToken.None); //Now add data to cache.. await _operation.AddCacheAsync(key, data); return(Ok(result.Result)); } else { var msg = this._localizer["NoDataFound"]?.Value; await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, msg + " while Fetching the Contact List resultset", "ContactListController.cs", "GetContactList"), CancellationToken.None); result.Result.ModelMessage = msg; return(Ok(result.Result)); } } else { var msg = this._localizer?["InternalServerError"]?.Value; await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, msg, "ContactListController.cs", "GetContactList"), CancellationToken.None); return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg)); } } await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Fetched the Contact List resultset from Cache key - " + key, "ContactListController.cs", "GetContactList"), CancellationToken.None); return(Ok(data)); } catch (Exception ex) { var msg = this._localizer?["InternalServerError"]?.Value; await _loggingFacade.LogExceptionAsync(ex, this.HttpContext?.Request?.Headers["UserName"], LogLevels.Error, "Error in GetContactList()", CancellationToken.None); return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg)); } }
public async Task <ApiResult <GenericPaginationResponse <Demographics> > > GetContactListAsync(LidTypeEnum LIDType, string LID, PaginationDemographics page) { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Contact List GetContactListAsync for " + LIDType.ToString() + ", Value - " + LID, "ContactListApi.cs", "GetContactListAsync"), CancellationToken.None); ApiResult <GenericPaginationResponse <Demographics> > response = new ApiResult <GenericPaginationResponse <Demographics> >(); try { response.Result = await _contactRepository.GetContactListAsync(LIDType, LID, page); await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Fetched the Contact List resultset from DB for " + LIDType.ToString() + ", Value - " + LID, "ContactListApi.cs", "GetContactListAsync"), CancellationToken.None); } catch (Exception) { throw; } return(response); }