public async Task <dynamic> SearchFunction(ListFilterLineViewModels request)
        {
            var list                = new List <DeliveryRequestLineViewModel>().AsEnumerable();
            var filteredList        = new List <DeliveryRequestLineViewModel>().AsEnumerable();
            int filteredResultCount = 0;
            int totalResultCount    = 0;

            var searchBy = request.search.value?.ToLower() ?? "" ?? "";
            var take     = request.length;
            var skip     = request.start;

            var orderBy  = "Id";
            var orderDir = true;

            if (request.order != null)
            {
                orderDir = request.order[0].dir.ToLower().Equals("asc");
                orderBy  = request.columns[request.order[0].column].data;
                orderBy  = (orderBy.Equals("actions", StringComparison.OrdinalIgnoreCase) ? "Id" : orderBy) + (orderDir ? "" : " desc");
            }

            var url      = $"api/GoodsOut/DeliveryRequest/Line/GetList/{request.IsActive}/{_customerId}/{request.HeaderId}";
            var response = await HttpClientHelper.ApiCall(url, Method.GET);

            if (response.IsSuccessful)
            {
                var result = response.Content;

                list = JsonConvert.DeserializeObject <List <dynamic> >(result).Select(x => new DeliveryRequestLineViewModel
                {
                    Id         = x.Id,
                    CustomerId = x.CustomerId,
                    IsActive   = x.IsActive,
                    //LineNumber = x.LineNumber ?? 0,
                    PickType           = x.PickType != null  ? x.PickType : "",
                    ProductDescription = x.Product != null ? x.Product : "",
                    Brand           = x.Brand != null ? x.Brand : "",
                    ItemDescription = x.Item != null ? x.Item : "",
                    UomDescription  = x.Uom != null ? x.Uom : "",
                    Quantity        = x.Quantity != null ? x.Quantity : 0
                }).ToList();

                filteredList = list.Where(x => x.PickType.ToLower().Contains(searchBy) ||
                                          x.ProductDescription.ToLower().Contains(searchBy) ||
                                          x.Brand.ToLower().Contains(searchBy) ||
                                          x.ItemDescription.ToLower().Contains(searchBy) ||
                                          x.UomDescription.ToLower().Contains(searchBy) ||
                                          x.Quantity.ToString().ToLower().Contains(searchBy)).OrderBy(orderBy, StringComparison.OrdinalIgnoreCase);
            }

            totalResultCount    = list.Count();
            filteredResultCount = filteredList.Count();
            filteredList        = filteredList.Skip(skip).Take(take);

            return(new { filteredList, filteredResultCount, totalResultCount });
        }
        public async Task <JsonResult> IndexJson(ListFilterLineViewModels request, bool?Planned, string StatusCode)
        {
            var helper = new ExpectedReceiptLineDataTableSearchHelper();
            var result = await helper.SearchFunction(request);

            var resultList = (IEnumerable <ExpectedReceiptViewModel.ExpectedReceiptLine>)result.filteredList;

            var data = resultList.Select(x => new
            {
                Actions = "<div class='btn-group' style='display:flex;'>" +
                          "<a class='btn btn-primary' href='#'><i class='fa fa-gear fa-fw'></i> Action</a>" +
                          "<a class='btn btn-primary dropdown-toggle' data-toggle='dropdown' href='#'>" +
                          "<span class='fa fa-caret-down' title='Toggle dropdown menu'></span>" +
                          "</a>" +
                          "<ul class='dropdown-menu' role='menu'>" +
                          (x.StatusCode.Equals("For Receiving", StringComparison.OrdinalIgnoreCase) ?
                           //"<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Edit") + "' onclick='btnClicked($(this))'><a>Edit</a></li>" +
                           // "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Details") + "' onclick='btnClicked($(this))'><a>Details</a></li>" +
                           "<li class='crud' data-id='" + x.Id + "' data-status='" + x.StatusCode + "' data-grn='" + x.GoodsReceivedNumber + "' data-request-url='" + Url.Action("Edit") + "' onclick='btnClicked($(this))'><a>Edit</a></li>" +
                           "<li class='crud' data-id='" + x.Id + "' data-status='" + x.StatusCode + "' data-grn='" + x.GoodsReceivedNumber + "' data-request-url='" + Url.Action("Details") + "' onclick='btnClicked($(this))'><a>Details</a></li>" +
                           (x.IsActive ?  "<li data-target = 'Delete' class='crud' data-id=" + x.Id + " data-status='" + x.StatusCode + "' data-grn='" + x.GoodsReceivedNumber + "' data-request-url='" + Url.Action("Delete") + "' onclick='btnClicked($(this))'><a>Delete</a></li>" :
                            "<li class='crud' data-id='" + x.Id + "' data-status='" + x.StatusCode + "' data-grn='" + x.GoodsReceivedNumber + "' data-request-url='" + Url.Action("Enable") + "' onclick='btnClicked($(this))'><a>Enable</a></li>") : "") +

                          (x.StatusCode.Equals("Received", StringComparison.OrdinalIgnoreCase) || x.StatusCode.Equals("Completed", StringComparison.OrdinalIgnoreCase) ?
                           "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Details") + "' onclick='btnClicked($(this))'><a>Details</a></li>" : "") +
                          "</ul>" +
                          "</div>",

                ExpiryDate      = x.ExpiryDate?.ToString("MMM. dd, yyyy") ?? "",
                ItemCode        = x.ItemCode,
                BrandName       = x.BrandName,
                ItemDescription = x.ItemDescription,
                Quantity        = x.Quantity,
                UomDescription  = x.UomDescription,
                IsActive        = x.IsActive
            });

            return(Json(new
            {
                draw = request.draw,
                recordsTotal = result.totalResultCount,
                recordsFiltered = result.filteredResultCount,
                data = data
            }));
            //return View(list);
        }
Example #3
0
        public async Task <JsonResult> IndexJson(ListFilterLineViewModels request)
        {
            var helper = new DeliveryRequestLineDataTableSearchHelper();
            var result = await helper.SearchFunction(request);

            var resultList = (IEnumerable <DeliveryRequestLineViewModel>)result.filteredList;

            var data = resultList.Select(x => new
            {
                Actions = "<div class='btn-group' style='display:flex;'>" +
                          "<a class='btn btn-primary' href='#'><i class='fa fa-gear fa-fw'></i> Action</a>" +
                          "<a class='btn btn-primary dropdown-toggle' data-toggle='dropdown' href='#'>" +
                          "<span class='fa fa-caret-down' title='Toggle dropdown menu'></span>" +
                          "</a>" +
                          "<ul class='dropdown-menu' role='menu'>" +
                          (x.IsActive && x.StatusId != 15 ? "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Edit") + "' onclick='btnClicked($(this))'><a>Edit</a></li>" : "") +
                          "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Details") + "' onclick='btnClicked($(this))'><a>Details</a></li>" +
                          (x.IsActive && x.StatusId != 15 ? "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Delete") + "' onclick='btnClicked($(this))'><a>Delete</a></li>" :
                           (x.StatusId != 15 ? "<li class='crud' data-id='" + x.Id + "' data-request-url='" + Url.Action("Enable") + "' onclick='btnClicked($(this))'><a>Enable</a></li>": "")) +
                          "</ul>" +
                          "</div>",
                PickType           = x.PickType,
                ProductDescription = x.ProductDescription,
                Brand           = x.Brand,
                ItemDescription = x.ItemDescription,
                UomDescription  = x.UomDescription,
                Quantity        = x.Quantity,
            });

            return(Json(new
            {
                draw = request.draw,
                recordsTotal = result.totalResultCount,
                recordsFiltered = result.filteredResultCount,
                data = data
            }));
        }
        public async Task <dynamic> SearchFunction(ListFilterLineViewModels request)
        {
            var list                = new List <ExpectedReceiptViewModel.ExpectedReceiptLine>().AsEnumerable();
            var filteredList        = new List <ExpectedReceiptViewModel.ExpectedReceiptLine>().AsEnumerable();
            int filteredResultCount = 0;
            int totalResultCount    = 0;

            var searchBy = request.search.value?.ToLower() ?? "" ?? "";

            var take = request.length;
            var skip = request.start;

            var orderBy  = "Id";
            var orderDir = true;

            if (request.order != null)
            {
                orderDir = request.order[0].dir.ToLower().Equals("asc");
                orderBy  = request.columns[request.order[0].column].data;
                orderBy  = (orderBy.Equals("actions", StringComparison.OrdinalIgnoreCase) ? "Id" : orderBy) + (orderDir ? "" : " desc");
            }

            var url = $"api/GoodsIn/ExpectedReceipt/GetByExpectedReceipt/{request.HeaderId}/{request.IsActive}/{_customerId}/";

            var response = await HttpClientHelper.ApiCall(url, Method.GET);

            if (response.IsSuccessful)
            {
                var result = response.Content;

                list = JsonConvert.DeserializeObject <List <dynamic> >(result).Select(x => new ExpectedReceiptViewModel.ExpectedReceiptLine
                {
                    Id                  = x.Id,
                    IsActive            = x.IsActive,
                    ExpectedReceiptId   = x.ExpectedReceiptId,
                    Quantity            = x.Quantity,
                    BrandId             = x.BrandId,
                    ProductId           = x.ProductId,
                    BrandName           = x.Brand != null ? x.Brand.Name : "",
                    Batch               = x.Batch,
                    ItemCode            = x.ItemCode,
                    ItemDescription     = x.ItemDescription != null ? x.ItemDescription : "",
                    ExpiryDate          = x.ExpiryDate,
                    UomDescription      = x.Uom != null ? x.Uom.Description : "",
                    ProductCode         = x.Product != null ? x.Product.Description : "",
                    StatusCode          = x.ExpectedReceipt != null ? x.ExpectedReceipt.Status.Name : "",
                    GoodsReceivedNumber = x.ExpectedReceipt != null ? x.ExpectedReceipt.GoodsReceivedNumber : ""
                }).ToList();

                filteredList = list.Where(x => (x.ExpiryDate?.ToString("MMM. dd, yyyy").ToLower().Contains(searchBy) ?? false) ||
                                          x.ItemCode.ToLower().Contains(searchBy) ||
                                          x.BrandName.ToLower().Contains(searchBy) ||
                                          x.ItemDescription.ToLower().Contains(searchBy) ||
                                          x.Quantity.ToString().ToLower().Contains(searchBy) ||
                                          x.UomDescription.ToLower().Contains(searchBy));
            }

            totalResultCount    = list.Count();
            filteredResultCount = filteredList.Count();
            filteredList        = filteredList.Skip(skip).Take(take);

            return(new { filteredList, filteredResultCount, totalResultCount });
        }