Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.92 KB | None | 0 0
  1. public bool CreateByKey(string key, Library.Types.ArticleRelationKeyType keyType)
  2.         {
  3.             try
  4.             {
  5.                 switch (keyType)
  6.                 {
  7.                     case Library.Types.ArticleRelationKeyType.SAN:
  8.                         ArticleKeySAN articleKeySAN = new ArticleKeySAN(key);
  9.  
  10.                         if (articleKeySAN.IsValid())
  11.                         {
  12.  
  13.                             ArticleRelation articleRelation = new ArticleRelation();
  14.                             articleRelation.KeyValue = key;
  15.                             articleRelation.Article = db.Articles.First(a => a.KeyValue == articleKeySAN.PlantNo);
  16.                             if ((!string.IsNullOrEmpty(articleKeySAN.OptionModel1)) && (articleKeySAN.OptionModel1 != "0000"))
  17.                             {
  18.                                 articleRelation.OptionModel1 = db.OptionModels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.OptionModel1));
  19.                                 if (articleRelation.OptionModel1 == null)
  20.                                     throw new Exception("OptionModel1 '" + articleKeySAN.OptionModel1 + "' not found in database");
  21.                             }
  22.                             if ((!string.IsNullOrEmpty(articleKeySAN.OptionModel2)) && (articleKeySAN.OptionModel2 != "0000"))
  23.                             {
  24.                                 articleRelation.OptionModel2 = db.OptionModels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.OptionModel2));
  25.                                 if (articleRelation.OptionModel2 == null)
  26.                                     throw new Exception("OptionModel2 '" + articleKeySAN.OptionModel2 + "' not found in database");
  27.                             }
  28.                             if ((!string.IsNullOrEmpty(articleKeySAN.OptionModel3)) && (articleKeySAN.OptionModel3 != "0000"))
  29.                             {
  30.                                 articleRelation.OptionModel3 = db.OptionModels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.OptionModel3));
  31.                                 if (articleRelation.OptionModel3 == null)
  32.                                     throw new Exception("OptionModel3 '" + articleKeySAN.OptionModel3 + "' not found in database");
  33.                             }
  34.                             articleRelation.SizeFrom = articleKeySAN.SizeFrom;
  35.                             articleRelation.SizeTo = articleKeySAN.SizeTo;
  36.                             if ((!string.IsNullOrEmpty(articleKeySAN.QualityLevel)) && (articleKeySAN.QualityLevel != "0000"))
  37.                             {
  38.                                 articleRelation.QualityLevel = db.QualityLevels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.QualityLevel));
  39.                                 if (articleRelation.QualityLevel == null)
  40.                                     throw new Exception("QualityLevel '" + articleKeySAN.QualityLevel + "' not found in database");
  41.                             }
  42.                             if ((!string.IsNullOrEmpty(articleKeySAN.Forst1)) && (articleKeySAN.Forst1 != "00"))
  43.                             {
  44.                                 articleRelation.Forst1 = db.Forsts.FirstOrDefault(a => (a.KeyValue == articleKeySAN.Forst1));
  45.                                 if (articleRelation.Forst1 == null)
  46.                                     throw new Exception("Forst1 '" + articleKeySAN.Forst1 + "' not found in database");
  47.                             }
  48.                             if ((!string.IsNullOrEmpty(articleKeySAN.Forst2)) && (articleKeySAN.Forst2 != "00"))
  49.                             {
  50.                                 articleRelation.Forst2 = db.Forsts.FirstOrDefault(a => (a.KeyValue == articleKeySAN.Forst2));
  51.                                 if (articleRelation.Forst2 == null)
  52.                                     throw new Exception("Forst2 '" + articleKeySAN.Forst2 + "' not found in database");
  53.                             }
  54.                             if ((!string.IsNullOrEmpty(articleKeySAN.Bio)) && (articleKeySAN.Bio != "00"))
  55.                             {
  56.                                 articleRelation.Bio = db.Bios.FirstOrDefault(a => (a.KeyValue == articleKeySAN.Bio));
  57.                                 if (articleRelation.Bio == null)
  58.                                     throw new Exception("Bio '" + articleKeySAN.Bio + "' not found in database");
  59.                             }
  60.  
  61.                             articleRelation.SourceType = SourceType.BdB_SAN;
  62.                             articleRelation.KeyType = keyType;
  63.  
  64.                             return Create(articleRelation);
  65.                         }
  66.                         else
  67.                         {
  68.                             this._error = "Ungültige SAN Nummer: "+key;
  69.                             return false;
  70.                         }
  71.  
  72.                     default: return false;
  73.                 }
  74.  
  75.             }
  76.             catch (Exception e)
  77.             {
  78.                 this._error = e.Message;
  79.                 return false;
  80.             }
  81.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement