Beispiel #1
0
        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));
        }