Beispiel #1
0
        //Delete => api/Questions/id
        public ActionResult Delete(int id)
        {
            try
            {
                string userName = User.Claims.First(u => u.Type == "UserName").Value;

                Questions question = _questionsRepository.GetQuestionByUserAndId(userName, id);
                if (question == null)
                {
                    return(NotFound("Couldn't find the Question"));
                }

                _questionsRepository.DeleteQuestion(question);

                if (_questionsRepository.SaveAll())
                {
                    return(Ok());
                }
                else
                {
                    _logger.LogWarning($"DateTime: {DateTime.Now} -- Error: Couldn't detele the question from the database");
                    return(BadRequest("Failed to delete the Question"));
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"DateTime:{DateTime.Now} -- Error:{e.Message}\n{e.StackTrace}");
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to get note"));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Delete(int id)
        {
            var deletedQuestion = await _questionsRepository.DeleteQuestion(id);

            if (deletedQuestion == null)
            {
                return(BadRequest("The question doesn't exist"));
            }

            var questionToReturn = _mapper.Map <QuestionForDetailDto>(deletedQuestion);

            return(Ok(questionToReturn));
        }
 public void DeleteQuestion(int qid)
 {
     qr.DeleteQuestion(qid);
 }
Beispiel #4
0
 public void DeleteQuestion(int QuestionID)
 {
     qr.DeleteQuestion(QuestionID);
 }
Beispiel #5
0
        public async Task <IActionResult> Edit([Bind("Title,Content,Tags,User,Id,PopularTags")] QuestionViewModel q, string submit)
        {
            if (submit == "Delete")
            {
                await questionsRepository.DeleteQuestion(q.Id);

                return(RedirectToAction("Index"));
            }
            else
            {
                var question = await questionsRepository.getQuestion(q.Id);

                if (ModelState.IsValid)
                {
                    question.Content = q.Content;
                    question.Title   = q.Title;
                    var oldTags = question.Tags;
                    await questionsRepository.UpdateQuestion(question);

                    if (q.Tags != null)
                    {
                        q.Tags = q.Tags + ",";
                        string[] listOfTags = (q.Tags).Split(",");

                        var listOfOldTags = oldTags.Select(x => x.Tag.TagContent).ToList <String>();

                        var newTags = listOfTags.Except(listOfOldTags).ToArray <String>();

                        var changedTags = listOfOldTags.Except(listOfTags).ToArray <String>();


                        for (int i = 0; i < newTags.Length - 1; i++)
                        {
                            Tag t = new Tag();
                            t.TagContent = newTags[i];
                            t.NumOfUses  = 1;
                            await tagsRepository.AddTags(t);

                            var addedTag = await tagsRepository.GetTagByName(newTags[i]);

                            TagPost tp = new TagPost();
                            tp.QuestionId = question.Id;
                            tp.TagId      = addedTag.Id;

                            await tagPostRepository.AddTagPost(tp);
                        }
                        for (int i = 0; i < changedTags.Length; i++)
                        {
                            Tag t = await tagsRepository.GetTagByName(changedTags[i]);

                            await tagPostRepository.DeleteTagFromQuestion(t, q.Id);

                            await tagsRepository.DeleteTags(t);
                        }
                    }
                    else
                    {
                        await tagPostRepository.DeleteAllTagsFromQuestion(q.Id);
                    }
                    return(RedirectToAction("Details", new { question.Id }));
                }
                q.PopularTags = await tagsRepository.GetPopular();
            }
            return(View(q));
        }
Beispiel #6
0
 public async Task <JsonResult> DeleteQuestion(Guid questionId)
 {
     return(await _repo.DeleteQuestion(questionId));
 }