Преглед на файлове

upgrade 09/2024
search news

sungroup преди 1 година
родител
ревизия
db6d6c3ce9

+ 102 - 1
WebPortal/WebPortal/Controllers/CustomerCareController.cs

@@ -75,7 +75,7 @@ namespace WebPortal.Controllers
                 SetWsClient(ref wsClient);
                 if (keywords != null && keywords.Trim().Length >= 2)
                 {
-                    // search content
+                    // search content (except news)
                     wsSearchTreeContentRequest wsRequest = new wsSearchTreeContentRequest(
                          BaseController.wsUser,
                          BaseController.wsPassword,
@@ -131,6 +131,53 @@ namespace WebPortal.Controllers
                         listTemp.Clear();
                     }
 
+                    // load news
+                    wsRequest = new wsSearchTreeContentRequest(
+                        BaseController.wsUser,
+                        BaseController.wsPassword,
+                        ProductType.NEWS,
+                        keywords,
+                        getCurrentLang());
+                    wsResponse = wsClient.wsSearchTreeContent(wsRequest);
+                    listContent = wsResponse.@return.listContent;
+                    if (listContent != null)
+                    {
+                        // add new group
+                        wsGetTreeByCodeRequest reqParent = new wsGetTreeByCodeRequest();
+                        reqParent.nodeCode = ProductType.NEWS;// wsUser, wsPassword, , getCurrentLang()
+                        reqParent.WsUser = wsUser;
+                        reqParent.WsPass = wsPassword;
+                        reqParent.lang = getCurrentLang();
+                        var group = wsClient.wsGetTreeByCode(reqParent).@return.listContent[0];
+                        groupModel = new ProductModel();
+                        groupModel.content = group;
+                        groupModel.listContent = listContent;
+                        // calculate page
+                        int totalPage = (int)Math.Ceiling(listContent.Length / 6m);
+                        int currentPage = 1;
+                        if (totalPage > 1)
+                        {
+                            groupModel.nextPage = currentPage + 1;
+                        }
+                        // store session
+                        HttpContext.Session.SetComplexData("newsModel", groupModel);
+
+                        // get max 6 news
+                        var groupNews = new ProductModel();
+                        groupNews.content = group;
+                        groupNews.nextPage = groupModel.nextPage;
+                        List<contentTreeObj> listNews = new List<contentTreeObj>();
+                        for (int i = 0; i< 6; i++)
+                        {
+                            if (i < listContent.Length)
+                            {
+                                listNews.Add(listContent[i]);
+                            }
+                        }
+                        groupNews.listContent = listNews.ToArray();
+                        listGroup.Add(groupNews);
+                    }
+
                     ViewBag.keywords = keywords;
                     return View(listGroup);
                 }
@@ -147,6 +194,60 @@ namespace WebPortal.Controllers
             }
         }
 
+        [HttpPost]
+        //[ValidateAntiForgeryToken]
+        public IActionResult NewsLoad()
+        {
+            try
+            {
+                ProductModel groupModel =  HttpContext.Session.GetComplexData<ProductModel>("newsModel");
+                int currentPage = groupModel.nextPage;
+                int totalPage = (int)Math.Ceiling(groupModel.listContent.Length / 6m);
+                if (totalPage > currentPage)
+                {
+                    groupModel.nextPage = currentPage + 1;
+                } else
+                {
+                    groupModel.nextPage = 0;
+                }
+                HttpContext.Session.SetComplexData("newsModel", groupModel);
+
+                // load next news
+                var groupNews = new ProductModel();
+                groupNews.content = groupModel.content;
+                groupNews.nextPage = groupModel.nextPage;
+                List<contentTreeObj> listNews = new List<contentTreeObj>();
+                for (int i = currentPage * 6; i < currentPage * 6 + 6; i++)
+                {
+                    if (i < groupModel.listContent.Length)
+                    {
+                        listNews.Add(groupModel.listContent[i]);
+                    }
+                }
+                groupNews.listContent = listNews.ToArray();
+
+                //model.listContent = listNews;
+                //var totalPage = wsResponse.@return.totalPage;
+                //int nextPage = int.Parse(page) + 1;
+                //if (totalPage >= nextPage)
+                //{
+                //    model.nextPage = nextPage;
+                //}
+
+                return PartialView("../Home/_News", groupNews);
+
+            }
+            catch (Exception ex)
+            {
+                log.Error("Exception NewsLoad", ex);
+                return Json(new
+                {
+                    error_code = "-1",
+                    error_content = "System failed"
+                });
+            }
+        }
+
         public ActionResult FaqDetail(String id)
         {
             // load FAQs

+ 57 - 7
WebPortal/WebPortal/Views/CustomerCare/Search.cshtml

@@ -34,11 +34,11 @@
                         <div class="title mb-4">
                             <span>@group.content.nodeName</span>
                             @*@if (group.listContent.Length > 6)
-                            {
-                                <a href="/CustomerCare/Search?parentCode=@group.content.nodeCode&keyword=@keywords" class="viewmore">
-                                    @Lang.ViewAll <img src="~/image/dot4.svg" class="ml-2" alt="more">
-                                </a>
-                            }*@
+                                {
+                                    <a href="/CustomerCare/Search?parentCode=@group.content.nodeCode&keyword=@keywords" class="viewmore">
+                                        @Lang.ViewAll <img src="~/image/dot4.svg" class="ml-2" alt="more">
+                                    </a>
+                                }*@
                         </div>
                         @if (group.content.nodeCode == ProductType.MB_SIM || group.content.nodeCode == ProductType.MB_MOBILE || group.content.nodeCode == ProductType.MB_CALLSMS)
                         {
@@ -78,8 +78,16 @@
                         }
                         else if (group.content.nodeCode == ProductType.NEWS)
                         {
-                            <div class="row  ">
-                                @Html.Partial("../Home/_News", group)
+                            <div class="container">
+                                <input type="hidden" id="currentPage" value="1" />
+                                <div class="row  " id="news">
+                                    @Html.Partial("../Home/_News", group)
+                                </div>
+                                <p class="text-center col-12">
+                                    <a class="btn-borblue" onclick="loadNews(6);" id="btnViewMore">
+                                        @Lang.MoreNews <img src="~/image/dot3.svg" class="ml-2" alt="more">
+                                    </a>
+                                </p>
                             </div>
                         }
                         else if (group.content.nodeCode == ProductType.BROADBAND)
@@ -320,6 +328,18 @@
 
 @section Scripts {
     <script>
+        $("#btnViewMore").hide();
+        $(document).ready(function () {
+            let nextPage = $("#nextPage").val();
+            let currentpage = $('#currentPage').val();
+            if (nextPage > 0) {
+                $("#btnViewMore").show();
+            } else {
+                $("#btnViewMore").hide();
+            }
+
+        })
+
         function loadFaqs(parentId) {
             console.log("loadFaqs " + parentId);
             var target = "body-" + parentId;
@@ -354,5 +374,35 @@
             }
         };
 
+        function loadNews(size) {
+            var currentPage = $('#currentPage').val();
+            $.ajax({
+                url: ('/CustomerCare/NewsLoad'),
+                type: "POST",
+                data: {
+                    __RequestVerificationToken: $('input[name=__RequestVerificationToken]').val(),
+                    size: size,
+                    page: currentPage,
+                    preview: "@ViewBag.preview"
+                },
+                success: function (result) {
+                    // remove page
+                    $("#nextPage").remove();
+                    $("#news").append(result);
+                    if ($("#nextPage").val() > 0) {
+                        // add page
+                        $('#currentPage').val($("#nextPage").val());
+                        $("#btnViewMore").show();
+                    } else {
+                        // hide view more data button
+                        $("#btnViewMore").hide();
+                    }
+                },
+                error: function (err) {
+                    console.log(err);
+                }
+            });
+        }
+
     </script>
 }

+ 0 - 1
WebPortal/WebPortal/Views/Home/News.cshtml

@@ -21,7 +21,6 @@
     }
 }
 
-
 <input type="hidden" id="currentPage" value="1" />
 <div class="pathway pt-5">
     <div class="container">