Beispiel #1
0
        public async Task <IActionResult> PutCollegeGroup([FromRoute] int id, [FromBody] CollegeGroupDTO collegeGroupDto)
        {
            if (id != collegeGroupDto.ID)
            {
                return(BadRequest());
            }

            var group = await _context.CollegeGroups.Include(g => g.Specialty).ThenInclude(s => s.College)
                        .FirstOrDefaultAsync(g => g.ID == collegeGroupDto.ID);

            group.Number      = collegeGroupDto.Number;
            group.SpecialtyId = collegeGroupDto.Specialty.ID;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CollegeGroupExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Beispiel #2
0
        public async Task <IActionResult> PostCollegeGroup([FromBody] CollegeGroupDTO collegeGroup)
        {
            _context.CollegeGroups.Add(new CollegeGroup()
            {
                ID          = collegeGroup.ID,
                Number      = collegeGroup.Number,
                SpecialtyId = collegeGroup.Specialty.ID
            });
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CollegeGroupExists(collegeGroup.ID))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }