public async Task <int> Create(Homework homework) { if (homework is null) { throw new ArgumentNullException(nameof(homework)); } var isInvalid = string.IsNullOrWhiteSpace(homework.Title) || string.IsNullOrWhiteSpace(homework.Description) || homework.Link == null; if (isInvalid) { throw new HomeworkException(HOMEWORK_IS_INVALID); } var homeworkId = await _homeworksRepository.Add(homework); if (homeworkId != default) { return(homeworkId); } else { return(default);
public async Task <int> Create(Homework homework) { // валидация if (homework is null) { throw new ArgumentNullException(nameof(homework)); } var isInvalid = homework.Link == null || string.IsNullOrWhiteSpace(homework.Title); if (isInvalid) { throw new BusinessException(HOMEWORK_IS_INVALID); } var homeworkId = await _homeworksRepository.Add(homework); return(homeworkId); }