public void AddVideo(AddVideoData data, int userId) { var user = this.context.Users.SingleOrDefault(x => x.Id == userId); if (user == null) { throw new ServiceException("User Not Found!"); } var videoTopic = new VideoTopic { Adherence = data.Adherence, TopicId = data.TopicId, VideoId = data.VideoId, }; try { this.context.VideosTopics.Add(videoTopic); this.context.SaveChanges(); } catch { throw new ServiceException("Addng Video to Topic failed. Pobably Video already belongs to Topic!"); } }
public IActionResult AddVideoToTopic([FromBody] AddVideoData data) { try { var userData = jwtService.ParseData(this.User); this.topicService.AddVideo(data, userData.UserId); return(Ok()); } catch (ServiceException e) { return(BadRequest(e.Message)); } }