public async Task <IActionResult> PutComment(int id, Comment comment) { if (id != comment.CommentId) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserIdExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCourse(int id, InputCourseDTO courseDTO) { Course course = _mapper.Map <Course>(courseDTO); Course existingEntry = await _context.Course.FindAsync(id); if (existingEntry == null) { return(BadRequest()); } existingEntry.Content = course.Content; existingEntry.Title = course.Title; existingEntry.CoursePrerequisiteMainCourse = course.CoursePrerequisiteMainCourse; existingEntry.Rating = courseDTO.Difficulty; _context.Update(existingEntry); await _context.SaveChangesAsync(); return(Ok(existingEntry)); }