public async Task CreateAsync(string name) { var hasRole = await repository.GetSingleAsync(x => x.Name.Equals(name)); if (hasRole != null) { throw new Exception(string.Format(Language.Duplicate, Language.Name)); } var role = builder.WithName(name) .Build(); role.Validate(); await repository.CreateAsync(role); }
public async Task CreateAsync(string name, int roleGroup) { var hasRole = await repository.GetByNameAsync(name); if (hasRole != null) { DomainEvent.Raise(new DomainNotification("DuplicateName", string.Format(Language.Duplicate, Language.Name))); } else { var role = builder.WithName(name) .WithRoleGroup(roleGroup) .Build(); if (role.IsValid()) { await repository.CreateAsync(role); } } }