public async Task <ActionResult> Paging(SaleOrderFindDTO findDTO)
 {
     return(PartialView(await handler.GetList(findDTO)));
 }
Esempio n. 2
0
        //-> GetList
        public async Task <GetListDTO <vSaleOrderDTO> > GetList(SaleOrderFindDTO findDTO)
        {
            /*
             * IQueryable<tblSaleOrder> records = from s in db.tblSaleOrders
             *                                 join c in db.tblCustomers on s.customerID equals c.id
             *                                 where s.deleted == null
             *                                 && (string.IsNullOrEmpty(findDTO.code) ? 1 == 1 : s.code.Contains(findDTO.code))
             *                                 && (string.IsNullOrEmpty(findDTO.status) ? 1 == 1 : s.status == findDTO.status)
             *                                 && (string.IsNullOrEmpty(findDTO.customer) ? 1 == 1 : c.firstName.Contains(findDTO.customer))
             *                                 orderby s.id ascending
             *                                 select s;
             *
             * return await Listing(findDTO.currentPage, records);
             */

            var         session = HttpContext.Current.Session;
            UserViewDTO user    = (UserViewDTO)session["user"];
            int         _user   = 0;

            if (user != null)
            {
                _user = user.id;
                if (user.user_Profile == 1)
                {
                    _user = -1;
                }
            }

            /*
             * IQueryable<SaleOrderFindResultDTO> query = from s in db.vSaleOrders
             *                                         //join c in db.tblCustomers on s.cust_CustomerID equals c.id
             *                                         where s.slor_Deleted == null
             *                                         && (string.IsNullOrEmpty(findDTO.code) ? 1 == 1 : s.cust_Code.Contains(findDTO.code))
             *                                         && (string.IsNullOrEmpty(findDTO.status) ? 1 == 1 : s.slor_Status == findDTO.status)
             *                                         && (string.IsNullOrEmpty(findDTO.customer) ? 1 == 1 : s.cust_FirstName.Contains(findDTO.customer))
             *                                         && (findDTO.customerID == 0 ? 1 == 1 : s.cust_CustomerID == findDTO.customerID)
             *                                         //&& (_user == -1 ? 1 == 1 : c.cust_UserID == _user)
             *                                         select new SaleOrderFindResultDTO
             *                                         {
             *                                             id = s.slor_SaleOrderID,
             *                                             code = s.slor_Code,
             *                                             date = s.slor_Date,
             *                                             firstName = s.cust_FirstName,
             *                                             total = s.slor_Total,
             *                                             status = s.slor_Status
             *                                         };
             */
            //return await Listing(findDTO.currentPage, records);


            var query = db.vSaleOrders.Where(x => x.slor_Deleted == null &&
                                             (string.IsNullOrEmpty(findDTO.code) ? 1 == 1                    : x.cust_Code.Contains(findDTO.code)) &&
                                             (string.IsNullOrEmpty(findDTO.status) ? 1 == 1                  : x.slor_Status == findDTO.status) &&
                                             (string.IsNullOrEmpty(findDTO.customer) ? 1 == 1                : x.cust_FirstName.Contains(findDTO.customer) || x.cust_LastName.Contains(findDTO.customer)) &&
                                             (string.IsNullOrEmpty(findDTO.slor_SourceOfSupply) ? 1 == 1     : x.slor_SourceOfSupply.ToString() == findDTO.slor_SourceOfSupply) &&
                                             (string.IsNullOrEmpty(findDTO.slor_TruckNo) ? 1 == 1            : x.slor_TruckNo.Contains(findDTO.slor_TruckNo)) &&
                                             (string.IsNullOrEmpty(findDTO.slor_DocNo) ? 1 == 1              : x.slor_DocNo.Contains(findDTO.slor_DocNo)) &&
                                             (string.IsNullOrEmpty(findDTO.slor_ShipmentNo) ? 1 == 1         : x.slor_ShipmentNo.Contains(findDTO.slor_ShipmentNo)) &&
                                             (string.IsNullOrEmpty(findDTO.slor_TruckDriverPhoneNo) ? 1 == 1 : x.slor_TruckDriverPhoneNo.Contains(findDTO.slor_TruckDriverPhoneNo)) &&
                                             (string.IsNullOrEmpty(findDTO.slor_Code) ? 1 == 1 : x.slor_Code.Contains(findDTO.slor_Code)) &&
                                             (string.IsNullOrEmpty(findDTO.slor_SONo) ? 1 == 1 : x.slor_SONo.Contains(findDTO.slor_SONo)) &&
                                             (string.IsNullOrEmpty(findDTO.shipMode) ? 1 == 1 : x.slor_ShipConidtion.Contains(findDTO.shipMode)) &&
                                             (findDTO.customerID == 0 ? 1 == 1                               : x.cust_CustomerID == findDTO.customerID)
                                             );


            DateTime?fromDate = null;
            DateTime?toDate   = null;


            if (!string.IsNullOrEmpty(findDTO.slor_RequiredDate_From) && !string.IsNullOrEmpty(findDTO.slor_RequiredDate_To))
            {
                fromDate = DateTime.ParseExact(findDTO.slor_RequiredDate_From, ConstantHelper.ddMMyyyy_DASH_SEPARATOR, CultureInfo.InvariantCulture);
                toDate   = DateTime.ParseExact(findDTO.slor_RequiredDate_To, ConstantHelper.ddMMyyyy_DASH_SEPARATOR, CultureInfo.InvariantCulture);
            }

            if (!string.IsNullOrEmpty(findDTO.slor_RequiredDate_From) && !string.IsNullOrEmpty(findDTO.slor_RequiredDate_To))
            {
                query = query.Where(x => DbFunctions.TruncateTime(x.slor_RequiredDate) >= DbFunctions.TruncateTime(fromDate) && DbFunctions.TruncateTime(x.slor_RequiredDate) <= DbFunctions.TruncateTime(toDate));
            }



            return(await ListingHandler(findDTO.currentPage, query.AsQueryable().OrderBy($"{findDTO.orderBy} {findDTO.orderDirection}")));
        }