Facebook
From Scorching Crocodile, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 51
  1.     public static int GetDictionaryMaxNr(DictionaryTypeEnum dictType, int unitId, DatabaseContext db)
  2.         {
  3.             var result = db.DictionariesValues
  4.                 .Where(x =>
  5.                 x.DictionaryTypeValue == dictType &&
  6.                 x.EntityStatus == EntityStatus.esActive
  7.                 )
  8.                 .OrderByDescending(x => x.Nr)
  9.                 .Select(x =>
  10.                 x.Nr);
  11.  
  12.             if (result.Count() == 0)
  13.             {
  14.                 return 1;
  15.             }
  16.  
  17.             if (result.Max() != result.Count())
  18.             {
  19.                 //pierwszy "wolny" nr
  20.                 int i = result.Count();
  21.                 foreach (var nr in result)
  22.                 {
  23.                     if (i != nr)
  24.                     {
  25.                         return i;
  26.                     }
  27.                     i--;
  28.                 }
  29.             }
  30.  
  31.             return result.Count() + 1;
  32.  
  33.         }