示例#1
0
        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);
示例#2
0
        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);
        }