예제 #1
0
        public async Task <SchoolDto> Add(SchoolInputDto input)
        {
            var school = new Entity.School()
            {
                Name    = input.Name,
                Address = input.Address,
            };
            await _dbContext.Schools.AddAsync(school);

            await _dbContext.SaveChangesAsync();

            return(_dtoFactory.CreateDto(school));
        }
예제 #2
0
        public async Task <SchoolDto> Update(int id, SchoolInputDto update)
        {
            var school = await _dbContext.Schools.FirstOrDefaultAsync(x => x.SchoolId == id);

            if (school == null)
            {
                throw new NotFoundException();
            }

            school.Name    = update.Name;
            school.Address = update.Address;

            await _dbContext.SaveChangesAsync();

            return(_dtoFactory.CreateDto(school));
        }
예제 #3
0
            public async Task <ActionResult <SchoolDto> > Put(int id, [FromBody] SchoolInputDto update)
            {
                var dto = await _schoolService.Update(id, update);

                return(Ok(dto));
            }
예제 #4
0
            public async Task <ActionResult <SchoolDto> > Post([FromBody] SchoolInputDto input)
            {
                var school = await _schoolService.Add(input);

                return(CreatedAtAction(nameof(Get), new { id = school.SchoolId }, school));
            }