コード例 #1
0
        public void Add(Major major)
        {
            ValidateMajor(major);
            ValidateDuplicatedMajor(major);

            _majorRepository.Add(major);
        }
コード例 #2
0
ファイル: MajorsController.cs プロジェクト: kuroza/UBD-TABS
        public async Task <IActionResult> CreateMajor([FromBody] SaveMajorResource majorResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var major = mapper.Map <SaveMajorResource, Major>(majorResource);

            var nameExist = await repository.MajorNameExist(major);

            if (nameExist != null)
            {
                return(Conflict("Major name already exists"));
            }

            repository.Add(major);
            await unitOfWork.CompleteAsync();

            major = await repository.GetMajor(major.Id);

            var result = mapper.Map <Major, MajorResource>(major);

            return(Ok(result));
        }