Пример #1
0
        public async Task Delete(string commentId, string id)
        {
            User user = await _sessionService.GetUser();

            if (user == null)
            {
                _logger.LogWarning("You cannot delete comment if you are not logged in");
                throw HttpError.Unauthorized("You cannot delete comment if you are not logged in");
            }

            Response response = await _responseRepository.GetById(id);

            if (response == null)
            {
                _logger.LogWarning($"Response {id} does not exist");
                throw HttpError.NotFound($"Response {id} does not exist");
            }

            if (response.CommentId != commentId)
            {
                throw HttpError.NotFound("");
            }

            if (response.AuthorId != user.Id)
            {
                _logger.LogWarning($"Response {id} does not belong to user");
                throw HttpError.Forbidden($"Response {id} does not belong to user");
            }

            await _responseRepository.Delete(id);
        }
Пример #2
0
        public IActionResult Delete(String name)
        {
            UserResponse deletedItem = repository.Delete(name);

            if (deletedItem != null)
            {
                TempData["message"] = $"{deletedItem.Name} was deleted";
            }
            return(RedirectToAction("Index"));
        }