Exemple #1
0
        public async Task <IActionResult> PostCourseSkill([FromBody] CourseSkill courseSkill)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CourseSkill.Add(courseSkill);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CourseSkillExists(courseSkill.CourseId, courseSkill.SkillId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetCourseSkill", new { id = courseSkill.CourseId }, courseSkill));
        }
Exemple #2
0
        public async Task <IActionResult> DeleteCourseSkill([FromBody] CourseSkill courseSkill)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingCourseSkill = await _context.CourseSkill
                                      .SingleOrDefaultAsync(m => m.CourseId == courseSkill.CourseId &&
                                                            m.SkillId == courseSkill.SkillId);

            if (existingCourseSkill == null)
            {
                return(NotFound());
            }

            _context.CourseSkill.Remove(existingCourseSkill);
            await _context.SaveChangesAsync();

            return(Ok(existingCourseSkill));
        }