コード例 #1
0
        public async Task <IActionResult> GetMrrProcess(
            [FromQuery] MrrProcessResourceParameter parameter
            )
        {
            var data = await _service.GetMrrProcessCollection(parameter).ConfigureAwait(false);

            return(Ok(data));
        }
コード例 #2
0
        public async Task <List <dynamic> > GetMrrProcessCollection(
            MrrProcessResourceParameter parameter
            )
        {
            var qry = _context.MrrProcesses
                      .Include(x => x.QualityEngineerOpened)
                      .Include(x => x.QualityEngineerClosed)
                      .Include(x => x.MrrProcessAttachments)
                      .Include(x => x.MrrProcessDefects)
                      .ThenInclude(x => x.ScrapCode)
                      .AsNoTracking()
                      .Where(
                x =>
                x.MrrOpenedTimestamp.Date >= parameter.Start.Date &&
                x.MrrOpenedTimestamp.Date <= parameter.End.Date
                )
                      .AsQueryable();

            if (parameter.Id > 0)
            {
                qry = qry.Where(x => x.MrrProcessId == parameter.Id);
            }

            var data = await qry.Select(
                x =>
                new
            {
                x.MrrProcessId,
                x.PartNumber,
                x.Analysis,
                x.Determination,
                x.Released,
                x.Returned,
                x.Scrapped,
                x.InspectorHours,
                x.EngineerHours,
                x.AdminHours,
                x.PeripheralCost,
                x.QualityEngineerOpenedId,
                x.QualityEngineerOpened,
                x.QualityEngineerClosedId,
                x.QualityEngineerClosed,
                x.MrrOpenedTimestamp,
                x.MrrClosedTimestamp,
                x.ModifiedDate,
                x.RowVersion,
                x.MrrProcessDefects,
                Attachments = x.MrrProcessAttachments
                              .Select(
                    a =>
                    new
                {
                    Uid = a.MrrProcessAttachmentId,
                    a.MrrProcessId,
                    Name   = a.FileName,
                    Status = "Done",
                    Url    = new Uri(
                        @$ "{_baseServerUrl}/mrrprocess/attachment/{a.MrrProcessAttachmentId}"
                        )
                }
                    )
                              .ToList <dynamic>(),
            }
                )
                       .ToListAsync()
                       .ConfigureAwait(false);

            var result = data.Select(
                x =>
            {
                var mrrNumber =
                    $"MRR-{x.MrrOpenedTimestamp.Year}-{x.MrrOpenedTimestamp.Month}{x.MrrOpenedTimestamp.Day}-P{x.MrrProcessId}";
                var statusText   = x.MrrClosedTimestamp is null ? "Open" : "Closed";
                var statusColor  = x.MrrClosedTimestamp is null ? "#DC3545" : "#19A974";
                var totalDefects = x.MrrProcessDefects.Sum(s => s.Qty);

                return(new
                {
                    x.MrrProcessId,
                    MrrNumber = mrrNumber,
                    StatusText = statusText,
                    StatusColor = statusColor,
                    TotalDefects = totalDefects,
                    x.PartNumber,
                    x.Analysis,
                    x.Determination,
                    x.Released,
                    x.Returned,
                    x.Scrapped,
                    x.InspectorHours,
                    x.EngineerHours,
                    x.AdminHours,
                    x.PeripheralCost,
                    x.QualityEngineerOpenedId,
                    x.QualityEngineerOpened,
                    x.QualityEngineerClosedId,
                    x.QualityEngineerClosed,
                    x.MrrOpenedTimestamp,
                    x.MrrClosedTimestamp,
                    x.ModifiedDate,
                    x.RowVersion,
                    x.MrrProcessDefects,
                    x.Attachments
                });
            }
                );

            return(result.ToList <dynamic>());
        }