public ActionResult DeleteConfirmed(int id)
        {
            Topic topic = repTopic.Read().FirstOrDefault(x => x.ID == id);

            repTopic.Delete(topic);
            return(RedirectToAction("Index"));
        }
示例#2
0
    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));

    }
示例#3
0
        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")));
            }
        }
示例#4
0
        public int DeleteTopic(int id)
        {
            SqlObject.CommandText = StoredProcedures.Topics.DeleteTopic;
            SqlObject.Parameters  = new object[] { id };
            int result = _repository.Delete(id);

            return(result);
        }
示例#5
0
        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>()));
        }
示例#6
0
        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"));
        }
示例#7
0
        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());
            }
        }
示例#8
0
 public void TestFindTopicByName()
 {
     topicRepository.Add(topic);
     Assert.AreEqual("Test", topicRepository.FindTopicByName("Test").Description);
     topicRepository.Delete(topic);
 }
示例#9
0
 public async Task DeleteTopic(long id)
 {
     await _repository.Delete(id);
 }