Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1.         public async Task<IEnumerable<AuditHeader>> GetOpen()
  2.         {
  3.             var lookup = new Dictionary<int, AuditHeader>();
  4.             using (var connection = await Conn.GetOpenConnectionAsync())
  5.             {
  6.                 string sql = @"SELECT AH.*, AD.*, Loc.*, Aud.*, Sh.*
  7.                                FROM AuditHeader as AH
  8.                                Inner Join AuditDtl as AD
  9.                                ON AH.ID = AD.AuditHeader_ID
  10.                                INNER JOIN Location as loc
  11.                                ON AH.Location_ID = Loc.ID
  12.                                INNEr JOIN Auditor as Aud
  13.                                ON AH.Auditor_ID = Aud.ID
  14.                                INNER JOIN Shift as sh
  15.                                ON AH.Shift_ID = sh.ID
  16.                                WHERE AH.EnteredDate is null ;";
  17.                 var headers = await connection.QueryAsync<AuditHeader, AuditDtl, Location, Auditor, Shift, AuditHeader>(
  18.                     sql,
  19.                     (h, d, l, a, s) =>
  20.                     {
  21.                         AuditHeader header;
  22.                         if (!lookup.TryGetValue(h.ID, out header))
  23.                         {
  24.                             lookup.Add(h.ID, header = h);
  25.                         }
  26.  
  27.                         if (header.AuditDtl == null)
  28.                             header.AuditDtl = new List<AuditDtl>();
  29.                         header.AuditDtl.Add(d);
  30.  
  31.                         if (header.Loction == null)
  32.                             header.Loction = new Location();
  33.                         header.Loction = l;
  34.  
  35.                        
  36.                         if (header.Auditor == null)
  37.                             header.Auditor = new Auditor();
  38.                         header.Auditor = a;
  39.  
  40.                        
  41.                         if (header.Shift == null)
  42.                             header.Shift = new Shift();
  43.                         header.Shift.ID = s.ID;
  44.                         header.Shift.ShiftDescription = s.ShiftDescription;
  45.  
  46.                         return header;
  47.                     }
  48.                     );
  49.  
  50.                 return headers.Distinct();
  51.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement