public void UpdateChangedProperties(FoodCategory foodCategory, out bool result, out string message) { string oldTags = _foodCategoryRepository.FindById(foodCategory.Id).Tags; if (oldTags != foodCategory.Tags) { _foodCategoryTagRepository.RemoveMultiple(_foodCategoryTagRepository.FindAll(x => x.FoodCategoryId == foodCategory.Id).ToList(), out result, out message); if (!string.IsNullOrEmpty(foodCategory.Tags)) { string[] tags = foodCategory.Tags.Split(';'); foreach (string t in tags) { var tagId = TextHelper.ToUnsignString(t); // Insert if there is a new tag if (!_tagRepository.FindAll(x => x.Id == tagId).Any()) { Tag tag = new Tag { Id = tagId, Active = true, Name = t.Trim(), Type = CommonConstants.TagType.FoodCategoryTag, UserCreated = foodCategory.UserCreated, UserModified = foodCategory.UserModified }; _tagRepository.Add(tag, out result, out message); } FoodCategoryTag foodCategoryTag = new FoodCategoryTag { FoodCategoryId = foodCategory.Id, TagId = tagId, Active = true, UserCreated = foodCategory.UserCreated, UserModified = foodCategory.UserModified }; _foodCategoryTagRepository.Add(foodCategoryTag, out result, out message); } } } _foodCategoryRepository.UpdateChangedProperties(foodCategory.Id, foodCategory, out result, out message); if (result) { SaveChanges(); } else { Dispose(); } }
public void Add(FoodCategory foodCategory, out bool result, out string message) { foodCategory.FoodCategoryTags = new List <FoodCategoryTag>(); // Tags if (!string.IsNullOrEmpty(foodCategory.Tags)) { string[] tags = foodCategory.Tags.Split(';'); foreach (string t in tags) { var tagId = TextHelper.ToUnsignString(t); // Insert if there is a new tag if (!_tagRepository.FindAll(x => x.Id == tagId).Any()) { Tag tag = new Tag { Id = tagId, Active = true, Name = t.Trim(), Type = CommonConstants.TagType.FoodCategoryTag, UserCreated = foodCategory.UserCreated, UserModified = foodCategory.UserModified }; _tagRepository.Add(tag, out result, out message); } FoodCategoryTag foodCategoryTag = new FoodCategoryTag { TagId = tagId, Active = true, UserCreated = foodCategory.UserCreated, UserModified = foodCategory.UserModified }; foodCategory.FoodCategoryTags.Add(foodCategoryTag); } } // Insert FoodCategory _foodCategoryRepository.Add(foodCategory, out result, out message); if (result) { SaveChanges(); } else { Dispose(); } }