public IActionResult Add(int memberID, int topicID) { var topic = _topicRepository.Get(a => a.ID == topicID); topic.MemberFollowedTopics.Add(new MemberFollowedTopic() { MemberID = memberID, TopicID = topicID }); return(RedirectToAction(nameof(Index))); }
public IHttpActionResult Delete(int topic_id) { if (!IsUserAdmin()) { // If user isn't admin return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized))); } ITopicRepository topicRepository = new TopicRepository(); IBlogRepository blogRepository = new BlogRepository(); // Get Topic from Db try { var dbBlogTopic = topicRepository.Get(topic_id); if (dbBlogTopic != null) { var blogsExistWithTopicID = blogRepository.GetAll().Where(x => x.TopicID == topic_id); if (blogsExistWithTopicID.Any()) { return(ResponseMessage(Request.CreateResponse(HttpStatusCode.MethodNotAllowed, "Failed to delete. One or multiple blogs have set this topic as blog topic"))); } topicRepository.Delete(dbBlogTopic.BlogTopicID); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent))); } else { return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, "Topic doesn't exist"))); } } catch { return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "Failed to update topic name"))); } }
internal Topic Get(Guid id) { TopicEntity entity = _topicRepo.Get(id); return(new Topic() { Id = entity.Id, Title = entity.Title, Creator = _memberService.Get(entity.IdCreator) }); }
public IHttpActionResult Put(int topic_id, [FromBody] BlogTopic blogTopic) { if (!IsUserAdmin()) { // If user isn't admin return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized))); } if (!ModelState.IsValid) { // IF Model State is invalid return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState))); } ITopicRepository topicRepository = new TopicRepository(); // Get Topic from Db try { var dbBlogTopic = topicRepository.Get(topic_id); if (dbBlogTopic != null) { // Update the value in db dbBlogTopic.Name = blogTopic.Name; topicRepository.Update(dbBlogTopic); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK))); } else { return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, "Topic doesn't exist"))); } } catch { return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "Failed to update topic name"))); } }
public void GetTopic_InexistentTopic_ShouldReturnNull() { Topic topicById = topicRepositoryInMemory.Get(oneTopic.Id); Assert.IsNull(topicById); }