コード例 #1
0
        public async Task <ActionResult> CreateSchoolAsync(School newSchool)
        {
            var alreadyExistingSchool = await schoolRepository.GetSchoolByNameAsync(newSchool.Name);

            if (alreadyExistingSchool != null)
            {
                return(BadRequest($"A School with the name '{newSchool.Name}' already exists in the Database"));
            }

            await schoolRepository.CreateSchoolAsync(newSchool);

            return(CreatedAtRoute(nameof(GetSchoolByNameAsync), new { name = newSchool.Name }, newSchool));
        }