public SongCategoryModel GetById(string id) { var songCategory = _songCategoryRepository.GetById(id); if (songCategory == null) { throw new NotFoundException(Messages.InvalidSongCategoryId); } return(SongCategoryMapper.ToSongCategoryModel(songCategory)); }
public void Add(SongCategoryModel songCategoryModel) { if (string.IsNullOrEmpty(songCategoryModel.Name)) { throw new ValidationException(Messages.SongCategoryNameRequired); } var instrumentByName = _songCategoryRepository.GetByName(songCategoryModel.Name); if (instrumentByName != null) { throw new ConflictException(Messages.SongCategoryNameAlreadyExists); } var songCategory = SongCategoryMapper.ToSongCategory(songCategoryModel); songCategory.Id = SecurityUtils.GenerateEntityId(); _songCategoryRepository.Add(songCategory); }
public void Update(string id, SongCategoryModel songCategoryModel) { if (string.IsNullOrEmpty(songCategoryModel.Name)) { throw new ValidationException(Messages.SongCategoryNameRequired); } var songCategory = _songCategoryRepository.GetById(id); if (songCategory == null) { throw new NotFoundException(Messages.InvalidSongCategoryId); } var instrumentByName = _songCategoryRepository.GetByName(songCategory.Name); if (instrumentByName != null && instrumentByName.Id != id) { throw new ConflictException(Messages.SongCategoryNameAlreadyExists); } SongCategoryMapper.RefreshSongCategory(songCategory, songCategoryModel); _songCategoryRepository.Update(songCategory); }