public Provider Add(Provider provider) { var _provider = _providerRepository.Add(provider); _unitOfWork.Commit(); if (!string.IsNullOrEmpty(provider.Tags)) { string[] tags = provider.Tags.Split(','); for (var i = 0; i < tags.Length; i++) { var tagId = StringHelper.ToUnsignString(tags[i]); if (_tagRepository.Count(x => x.ID == tagId) == 0) { Tag tag = new Tag(); tag.ID = tagId; tag.Name = tags[i]; tag.Type = CommonConstants.ProviderTag; _tagRepository.Add(tag); } ProviderTag providerTag = new ProviderTag(); providerTag.ProviderID = provider.ID; providerTag.TagID = tagId; _providerTagRepository.Add(providerTag); } } return(_provider); }
public async Task <IdNameModel> Create(ProviderTagCreateModel model) { if (string.IsNullOrWhiteSpace(model.Key)) { throw new ModelDamagedException("Key is null"); } if (model.Translations == null || !model.Translations.Any()) { throw new ModelDamagedException("Key is null"); } if (model.Translations.Count(z => z.IsDefault) != 1) { throw new ModelDamagedException("No default translation"); } model.Key = model.Key.ToLower(); var exists = await _providerTagRepository.Count(x => x.Key == model.Key && x.State == MREntityState.Active); if (exists > 0) { throw new EntityExistsException("1", "1", typeof(ProviderTag)); } ProviderTag tag = new ProviderTag { Key = model.Key, UserCreatedId = "TEST_USER_ID", State = MREntityState.Active, Translations = model.Translations.Select(x => new ProviderTagTranslation { IsDefault = x.IsDefault, LanguageCode = x.LanguageCode, Name = x.Name }).ToList() }; await _providerTagRepository.Insert(tag); return(new IdNameModel { Id = tag.Id, Name = tag.Translations.First(x => x.IsDefault).Name }); }