public ActionResult DeleteConfirmed(int id) { Topic topic = repTopic.Read().FirstOrDefault(x => x.ID == id); repTopic.Delete(topic); return(RedirectToAction("Index")); }
public IActionResult Delete(int[] topics) { /*------------------------------------------------------------------------------------------------------------------------ | Validate input \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(topics, nameof(topics)); /*------------------------------------------------------------------------------------------------------------------------ | Delete topics \-----------------------------------------------------------------------------------------------------------------------*/ foreach (var topicId in topics) { if (topicId < 0) { continue; } var topic = TopicRepository.Load(topicId); if (!topic.GetUniqueKey().StartsWith(_licenseRoot, StringComparison.InvariantCultureIgnoreCase)) { continue; } TopicRepository.Delete(topic); } /*------------------------------------------------------------------------------------------------------------------------ | Return default view \-----------------------------------------------------------------------------------------------------------------------*/ 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"))); } }
public int DeleteTopic(int id) { SqlObject.CommandText = StoredProcedures.Topics.DeleteTopic; SqlObject.Parameters = new object[] { id }; int result = _repository.Delete(id); return(result); }
public void TestEntityDelete() { var topic = new Topic("Nome teste"); var mockTeste = new Mock <IDeleteDB <Topic> >(); var topicRepository = new TopicRepository(mockTeste.Object); topicRepository.Delete(topic); mockTeste.Verify(x => x.DeleteRegister(It.IsAny <Topic>())); }
public RedirectToRouteResult Delete(string topicName) { TopicModel topic = _topicRepository.GetByName(topicName); if (!_topicRepository.IsUsedTopic(topicName)) { _topicRepository.Delete(topic); _topicRepository.Save(); return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Index")); }
public ActionResult Delete(int id, TopicViewModel model) { try { var repository = new TopicRepository(context); var topic = MapperHelper.Map <Topic>(model); repository.Delete(topic); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public void TestFindTopicByName() { topicRepository.Add(topic); Assert.AreEqual("Test", topicRepository.FindTopicByName("Test").Description); topicRepository.Delete(topic); }
public async Task DeleteTopic(long id) { await _repository.Delete(id); }