Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool CreateByKey(string key, Library.Types.ArticleRelationKeyType keyType)
- {
- try
- {
- switch (keyType)
- {
- case Library.Types.ArticleRelationKeyType.SAN:
- ArticleKeySAN articleKeySAN = new ArticleKeySAN(key);
- if (articleKeySAN.IsValid())
- {
- ArticleRelation articleRelation = new ArticleRelation();
- articleRelation.KeyValue = key;
- articleRelation.Article = db.Articles.First(a => a.KeyValue == articleKeySAN.PlantNo);
- if ((!string.IsNullOrEmpty(articleKeySAN.OptionModel1)) && (articleKeySAN.OptionModel1 != "0000"))
- {
- articleRelation.OptionModel1 = db.OptionModels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.OptionModel1));
- if (articleRelation.OptionModel1 == null)
- throw new Exception("OptionModel1 '" + articleKeySAN.OptionModel1 + "' not found in database");
- }
- if ((!string.IsNullOrEmpty(articleKeySAN.OptionModel2)) && (articleKeySAN.OptionModel2 != "0000"))
- {
- articleRelation.OptionModel2 = db.OptionModels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.OptionModel2));
- if (articleRelation.OptionModel2 == null)
- throw new Exception("OptionModel2 '" + articleKeySAN.OptionModel2 + "' not found in database");
- }
- if ((!string.IsNullOrEmpty(articleKeySAN.OptionModel3)) && (articleKeySAN.OptionModel3 != "0000"))
- {
- articleRelation.OptionModel3 = db.OptionModels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.OptionModel3));
- if (articleRelation.OptionModel3 == null)
- throw new Exception("OptionModel3 '" + articleKeySAN.OptionModel3 + "' not found in database");
- }
- articleRelation.SizeFrom = articleKeySAN.SizeFrom;
- articleRelation.SizeTo = articleKeySAN.SizeTo;
- if ((!string.IsNullOrEmpty(articleKeySAN.QualityLevel)) && (articleKeySAN.QualityLevel != "0000"))
- {
- articleRelation.QualityLevel = db.QualityLevels.FirstOrDefault(a => (a.KeyValue == articleKeySAN.QualityLevel));
- if (articleRelation.QualityLevel == null)
- throw new Exception("QualityLevel '" + articleKeySAN.QualityLevel + "' not found in database");
- }
- if ((!string.IsNullOrEmpty(articleKeySAN.Forst1)) && (articleKeySAN.Forst1 != "00"))
- {
- articleRelation.Forst1 = db.Forsts.FirstOrDefault(a => (a.KeyValue == articleKeySAN.Forst1));
- if (articleRelation.Forst1 == null)
- throw new Exception("Forst1 '" + articleKeySAN.Forst1 + "' not found in database");
- }
- if ((!string.IsNullOrEmpty(articleKeySAN.Forst2)) && (articleKeySAN.Forst2 != "00"))
- {
- articleRelation.Forst2 = db.Forsts.FirstOrDefault(a => (a.KeyValue == articleKeySAN.Forst2));
- if (articleRelation.Forst2 == null)
- throw new Exception("Forst2 '" + articleKeySAN.Forst2 + "' not found in database");
- }
- if ((!string.IsNullOrEmpty(articleKeySAN.Bio)) && (articleKeySAN.Bio != "00"))
- {
- articleRelation.Bio = db.Bios.FirstOrDefault(a => (a.KeyValue == articleKeySAN.Bio));
- if (articleRelation.Bio == null)
- throw new Exception("Bio '" + articleKeySAN.Bio + "' not found in database");
- }
- articleRelation.SourceType = SourceType.BdB_SAN;
- articleRelation.KeyType = keyType;
- return Create(articleRelation);
- }
- else
- {
- this._error = "Ungültige SAN Nummer: "+key;
- return false;
- }
- default: return false;
- }
- }
- catch (Exception e)
- {
- this._error = e.Message;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement