/// <summary> /// Creates the or get tag. /// </summary> /// <param name="tagName">Name of the tag.</param> /// <returns></returns> public TagViewModel CreateOrGetTag(string tagName) { Tag tagExist = unitOfWork.TagRepository.Get(filter: t => t.Name == tagName).FirstOrDefault(); if (tagExist != null) { return Mapper.Map<TagViewModel>(tagExist); } Tag newTag = new Tag { Name = tagName }; unitOfWork.TagRepository.Add(Mapper.Map<Tag>(newTag)); unitOfWork.Save(); return Mapper.Map<TagViewModel>(newTag); }
private TagViewModel CreateOrGetTag(string tagName) { Tag tagExist = tagRepository.GetAll().FirstOrDefault(t => t.Name == tagName); if (tagExist != null) { return Mapper.Map<TagViewModel>(tagExist); } Tag newTag = new Tag { Name = tagName }; tagRepository.Add(Mapper.Map<Tag>(newTag)); tagRepository.Save(); return Mapper.Map<TagViewModel>(newTag); }