示例#1
0
        public IActionResult Delete(int id)
        {
            if (id == 0)
            {
                return(BadRequest());
            }
            User user = _userData.GetById(id);

            if (user == null)
            {
                return(NotFound());
            }
            IEnumerable <Video>   userVideos   = _videoData.GetByOwnerId(user.Id);
            IEnumerable <Comment> userComments = _commentData.GetCommentsByUser(user.Id);

            foreach (var v in userVideos)
            {
                _videoData.Delete(v);
            }
            foreach (var c in userComments)
            {
                _commentData.Delete(c);
            }
            _userData.Delete(user);
            int loggedInUserId = int.Parse(HttpContext.Session.GetString("LoggedInUserId"));

            if (loggedInUserId == id)
            {
                HttpContext.Session.Remove("LoggedInUserId");
                HttpContext.Session.Remove("LoggedInUserRole");
                HttpContext.Session.Remove("LoggedInUserUsername");
            }
            var contentType = Request.ContentType;

            if (contentType != null)
            {
                if (contentType.Equals("application/json"))
                {
                    return(NoContent());
                }
                else if (contentType.Equals("text/html"))
                {
                    return(RedirectToAction(nameof(GetById), id));
                }
                else if (contentType.Equals("application/x-www-form-urlencoded"))
                {
                    return(RedirectToAction(nameof(GetById), id));
                }
                return(StatusCode(415));
            }
            return(Json("Success"));
        }
示例#2
0
        public IActionResult DeleteComment(long id)
        {
            var loggedInUserId = HttpContext.Session.GetString("LoggedInUserId");

            if (loggedInUserId == null)
            {
                return(StatusCode(401));
            }
            User    user    = _userData.GetById(long.Parse(loggedInUserId));
            Comment comment = _commentData.GetById(id);

            if (user == null || comment == null)
            {
                return(BadRequest());
            }
            if (user.Blocked == true)
            {
                return(StatusCode(401));
            }
            _commentData.Delete(comment);
            return(Json("Success"));
        }
示例#3
0
        public IActionResult DeleteVideo(int id)
        {
            Video video = _videoData.GetById(id);

            if (video == null)
            {
                return(NotFound());
            }
            List <Comment> comments = _commentData.GetCommentsByVideo(id).ToList();

            foreach (var c in comments)
            {
                _commentData.Delete(c);
            }
            _videoData.Delete(video);
            var contentType = Request.ContentType;

            if (contentType != null)
            {
                return(NoContent());
            }
            return(Json("Success"));
        }
示例#4
0
 public ActionResult DeleteConfirmed(int id)
 {
     _db.Delete(id);
     return(RedirectToAction("Index"));
 }