示例#1
0
        public async Task <ActionResult> List(DataSourceRequest command, SearchTrackingModel model)
        {
            // Works
            DateTime dateSearch = DateTime.Now;

            if (model.Datetime != null)
            {
                dateSearch = DateTime.Parse(model.Datetime, CultureInfo.InvariantCulture);
            }
            var Trackings = await _trackingService.GetTrackingByDateAndLine(model.LineCode, dateSearch);

            if (String.IsNullOrEmpty(model.SearchKeyword))
            {
                Trackings = Trackings.OrderByDescending(p => p.UpdatedDate).ToList();
            }

            var totalQuantity = Trackings.Sum(t => t.Quantity);

            var listTrackingModel = Trackings.Select(p => new TrackingModel()
            {
                Id            = p.Id,
                UpdatedDate   = p.UpdatedDate.ToShortDateString(),
                UserCreated   = p.UserCreated,
                LineCode      = p.LineCode,
                FGCode        = p.FGCode,
                Variant       = p.Variant,
                Cause         = p.Cause,
                CreatedDate   = p.CreatedDate.ToShortDateString(),
                Lot           = p.Lot,
                Quantity      = p.Quantity,
                Size          = p.Size,
                Where         = p.Where,
                TotalQuantity = totalQuantity
            }).AsQueryable();

            // Calculate the total number of records before paging
            var total = listTrackingModel.Count();


            // Apply paging
            if (command.Page > 0)
            {
                listTrackingModel = listTrackingModel.Skip((command.Page - 1) * command.PageSize);
            }
            listTrackingModel = listTrackingModel.Take(command.PageSize);

            var result = new DataSourceResult()
            {
                Data  = listTrackingModel.AsEnumerable(), // Process data (paging and sorting applied)
                Total = total                             // Total number of records
            };

            // Return the result as JSON
            return(Json(result));
        }
示例#2
0
        public async Task <ActionResult> ListManager(DataSourceRequest command, SearchTrackingModel model)
        {
            DateTime dateSearchStart;

            if (String.IsNullOrEmpty(model.FromDate))
            {
                dateSearchStart = DateTime.Now;
            }
            else
            {
                var culture = CultureInfo.CreateSpecificCulture("en-US");
                const DateTimeStyles styles = DateTimeStyles.None;
                if (!DateTime.TryParse(model.FromDate, culture, styles, out dateSearchStart))
                {
                    dateSearchStart = DateTime.Now;
                }
            }

            DateTime dateSearchEnd;


            if (String.IsNullOrEmpty(model.ToDate))
            {
                dateSearchEnd = DateTime.Now;
            }
            else
            {
                var culture = CultureInfo.CreateSpecificCulture("en-US");
                const DateTimeStyles styles = DateTimeStyles.None;
                if (!DateTime.TryParse(model.ToDate, culture, styles, out dateSearchEnd))
                {
                    dateSearchEnd = DateTime.Now;
                }
            }

            var Trackings = await _trackingService.GetTrackingByTwoDateAndLine(model.LineCode, dateSearchStart, dateSearchEnd);

            if (String.IsNullOrEmpty(model.SearchKeyword))
            {
                Trackings = Trackings.OrderByDescending(p => p.UpdatedDate).ToList();
            }


            var totalQuantity = Trackings.Sum(t => t.Quantity);


            var listTrackingModel = Trackings.Select(p => new TrackingModel()
            {
                Id            = p.Id,
                UpdatedDate   = p.UpdatedDate.ToShortDateString(),
                UserCreated   = p.UserCreated,
                LineCode      = p.LineCode,
                FGCode        = p.FGCode,
                Variant       = p.Variant,
                Cause         = p.Cause,
                CreatedDate   = p.CreatedDate.ToShortDateString(),
                Lot           = p.Lot,
                Quantity      = p.Quantity,
                Size          = p.Size,
                Where         = p.Where,
                TotalQuantity = totalQuantity
            }).AsQueryable();

            // Calculate the total number of records before paging
            var total = listTrackingModel.Count();


            // Apply paging
            if (command.Page > 0)
            {
                listTrackingModel = listTrackingModel.Skip((command.Page - 1) * command.PageSize);
            }
            listTrackingModel = listTrackingModel.Take(command.PageSize);

            var result = new DataSourceResult()
            {
                Data  = listTrackingModel.AsEnumerable(), // Process data (paging and sorting applied)
                Total = total                             // Total number of records
            };

            // Return the result as JSON
            return(Json(result));
        }