Ejemplo n.º 1
0
        public ResponseModel GetCustomerChatHistory([FromBody] GetChatHistoryModel chatHistory)
        {
            List <CustomerChatHistory> customerChatHistory = new List <CustomerChatHistory>();
            ResponseModel objResponseModel = new ResponseModel();
            int           statusCode       = 0;
            string        statusMessage    = "";

            try
            {
                string       token        = Convert.ToString(Request.Headers["X-Authorized-Token"]);
                Authenticate authenticate = new Authenticate();
                authenticate = SecurityService.GetAuthenticateDataFromToken(_radisCacheServerAddress, SecurityService.DecryptStringAES(token));

                CustomerChatCaller customerChatCaller = new CustomerChatCaller();

                customerChatHistory = customerChatCaller.CustomerChatHistory(new CustomerChatService(_connectionString), chatHistory.ChatId);

                //////////////////////////Paging//////////////////////

                // Get's No of Rows Count
                int count = customerChatHistory.Count;

                // Parameter is passed from Query string if it is null then it default Value will be pageNumber:1
                int CurrentPage = chatHistory.pageNumber;

                // Parameter is passed from Query string if it is null then it default Value will be pageSize:20
                int PageSize = chatHistory.pageSize;

                // Display TotalCount to Records to User
                int TotalCount = count;

                // Calculating Totalpage by Dividing (No of Records / Pagesize)
                int TotalPages = (int)Math.Ceiling(count / (double)PageSize);

                // Returns List of Customer after applying Paging
                var customerChats = customerChatHistory.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList();

                // if CurrentPage is greater than 1 means it has previousPage
                var previousPage = CurrentPage > 1 ? "Yes" : "No";

                // if TotalPages is greater than CurrentPage means it has nextPage
                var nextPage = CurrentPage < TotalPages ? "Yes" : "No";

                // Object which we are going to send in header
                var paginationMetadata = new
                {
                    totalCount  = TotalCount,
                    pageSize    = PageSize,
                    currentPage = CurrentPage,
                    totalPages  = TotalPages,
                    previousPage,
                    nextPage
                };

                //////////////////////////Paging End////////////////////////

                statusCode =
                    customerChats.Count == 0 ?
                    (int)EnumMaster.StatusCode.RecordNotFound : (int)EnumMaster.StatusCode.Success;

                statusMessage = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)statusCode);


                objResponseModel.Status       = true;
                objResponseModel.StatusCode   = statusCode;
                objResponseModel.Message      = statusMessage;
                objResponseModel.ResponseData = customerChats;

                HttpContext.Response.Headers.Add("Paging-Headers", JsonConvert.SerializeObject(paginationMetadata));
            }
            catch (Exception)
            {
                throw;
            }
            return(objResponseModel);
        }