Example #1
0
        public async Task <IActionResult> RecieveOrders(DataSourceRequest command,
                                                        ReceiveOrderListModel model)
        {
            var(receiveOrderListModel, totalCount) = await _processOrderService.PrepareReceiveOrderListModel(model, command.Page, command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data  = receiveOrderListModel,
                Total = totalCount
            };

            return(Json(gridModel));
        }
        public async Task <(IEnumerable <History> receiveOrderListModel, int totalCount)> PrepareReceiveOrderListModel(ReceiveOrderListModel model, int pageIndex, int pageSize)
        {
            try
            {
                var usrType = (int)_workContext.CurrentCustomer.ClientId;

                var query = _historyRepository.Table;

                if (usrType == 1 || usrType == 3 || usrType == 12)
                {
                    query = (from h in query
                             join l in _logonRepository.Table on h.HuserLogon equals l.LogonId
                             where h.HclientId == (int)_workContext.CurrentCustomer.ClientId &&
                             l.UserType == 3 &&
                             h.Hstatus == model.strStatus
                             select new History
                    {
                        Hpo = h.Hpo,
                        HshipName = h.HshipId,
                        HvendorName = h.HvendorName,
                        Hdate = h.Hdate,
                        Hdescription = h.Hdescription,
                        Hoitem = h.Hoitem
                    }).Distinct();
                }

                if (usrType == 2 || usrType == 6 || usrType == 7 || usrType == 8 || usrType == 10)
                {
                    query = (from h in query
                             where h.HclientId == (int)_workContext.CurrentCustomer.ClientId &&
                             h.Hstatus == model.strStatus
                             select new History
                    {
                        Hpo = h.Hpo,
                        HshipName = h.HshipId,
                        HvendorName = h.HvendorName,
                        Hdate = h.Hdate,
                        Hdescription = h.Hdescription,
                        Hoitem = h.Hoitem
                    }).Distinct();
                }

                if (usrType == 4)
                {
                    query = (from h in query
                             join l in _logonRepository.Table on h.HuserLogon equals l.LogonId
                             where h.HclientId == (int)_workContext.CurrentCustomer.ClientId &&
                             l.UserType == 4 &&
                             h.Hstatus == model.strStatus
                             select new History
                    {
                        Hpo = h.Hpo,
                        HshipName = h.HshipId,
                        HvendorName = h.HvendorName,
                        Hdate = h.Hdate,
                        Hdescription = h.Hdescription,
                        Hoitem = h.Hoitem
                    }).Distinct();
                }


                if (model.txtSort == "A")
                {
                    query = query.OrderBy(h => h.Hdate);
                }

                if (model.txtSort == "D")
                {
                    query = query.OrderByDescending(h => h.Hdate);
                }

                if (!string.IsNullOrEmpty(model.txtDept))
                {
                    query = query.Where(h => h.HshipId == model.txtDept);
                }

                if (!string.IsNullOrEmpty(model.BDate))
                {
                    query = query.Where(h => h.Hdate >= Convert.ToDateTime(model.BDate));
                }

                if (!string.IsNullOrEmpty(model.EDate))
                {
                    query = query.Where(h => h.Hdate <= Convert.ToDateTime(model.EDate));
                }

                if (!string.IsNullOrEmpty(model.txtPO))
                {
                    query = query.Where(h => h.Hpo == model.txtPO);
                }

                if (!string.IsNullOrEmpty(model.txtVendor))
                {
                    query = query.Where(h => h.HvendorName == model.txtVendor);
                }

                if (!string.IsNullOrEmpty(model.txtItem))
                {
                    query = query.Where(h => h.Hoitem == model.txtItem);
                }

                var RecieveOrder = query.ToList();
                int totalCount   = RecieveOrder.Count;
                int pageOffSet   = (Convert.ToInt32(pageIndex) - 1) * 10;
                RecieveOrder = RecieveOrder.Skip(pageOffSet).Take(Convert.ToInt32(pageSize)).ToList();

                return(RecieveOrder, totalCount);
            }
            catch (Exception ex)
            {
            }

            return(null, 0);
        }