//Forming the Unique ChacheId private string UniqueCachingKey(ContactListInput pageinput) { int merchantId = Convert.ToInt32(pageinput.LIDValue); PaginationDemographics page = pageinput.Page; var key = _localizer["UniqueKey"] + "_" + merchantId; if (page.PageSize > 0) { key = key + "_PageSize_" + page.PageSize; } if (page.SkipRecordNumber > 0) { key = key + "_SkipRecord_" + page.SkipRecordNumber; } if (page.SortField != null) { key = key + "_" + page.SortField + "_" + page.SortFieldByAsc; } if (page.FilterContact != null) { key = key + "_FilterContact_" + page.FilterContact; } if (page.FilterLast4 != null) { key = key + "_FilterLast4_" + page.FilterLast4; } if (page.FilterRole != null) { key = key + "_FilterRole_" + page.FilterRole; } return(key); }
private ContactListInput GetContactListObject() { ContactListInput pageInput = new ContactListInput(); pageInput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Terminal; pageInput.LIDValue = "123456"; PaginationDemographics page = new PaginationDemographics(); page.FilterContact = "wa"; page.PageSize = 100; page.SortField = "Contact"; page.SortFieldByAsc = true; pageInput.Page = page; return(pageInput); }
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)); } }