public void AddBlacklistItem(Blacklist blacklist)
        {
            bool existsInList = false;

            if (blacklist != null)
            {
                for (int j = 0; j < blacklistDAO.GetAll().Count; j++)
                {
                    if (blacklistDAO.GetAll()[j].Track.Id.Equals(blacklist.Track.Id))
                    {
                        existsInList = true;
                        throw new APIException(StatusCodes.Status409Conflict, "The track is already blacklisted");
                    }
                }
                if (!existsInList)
                {
                    blacklistDAO.Add(blacklist);
                    for (int i = 0; i < ControllerRegistry.GetMusicrequestController().GetAllMusicRequests().Count; i++)
                    {
                        if (ControllerRegistry.GetMusicrequestController().GetAllMusicRequests()[i].Track.Id == blacklist.Track.Id)
                        {
                            ControllerRegistry.GetMusicrequestController().DeleteMusicrequest(ControllerRegistry.GetMusicrequestController().GetAllMusicRequests()[i].Id);
                        }
                    }
                }
            }
            else
            {
                throw new APIException(StatusCodes.Status422UnprocessableEntity);
            }
        }
 public void DownvoteMusicrequest(int id, int userid)
 {
     musicrequestVotesDAO.AddDownvote(id, ControllerRegistry.GetUserController().GetUser(userid));
 }
        public void AddMusicrequest(Musicrequest musicrequestFromApp)
        {
            if (musicrequestFromApp != null)
            {
                List <Musicrequest> musicrequests = GetAllMusicRequests();
                bool isRequestedBefore            = false;
                //Går igennem blacklisten
                for (int j = 0; j < ControllerRegistry.GetBlacklistController().GetBlacklist().Count; j++)
                {
                    //Hvis sangen findes i blacklist
                    if (musicrequestFromApp.Track.Id.Equals(ControllerRegistry.GetBlacklistController().GetBlacklist()[j].Track.Id))
                    {
                        throw new APIException(StatusCodes.Status403Forbidden, "The track is blacklisted by the admin");
                    }
                }

                // Går igennem alle musicrequests
                for (int i = 0; i < musicrequests.Count; i++)
                {
                    // Hvis sangen allerede er under musicrequests
                    if (musicrequestFromApp.Track.Id.Equals(musicrequests[i].Track.Id))
                    {
                        isRequestedBefore = true;
                        //Går alle Upvotes på den enkle allerede eksiterende musicrequest igennem
                        for (int j = 0; j < musicrequests[i].Upvotes.Count; j++)
                        {
                            //Hvis brugeren allerede har upvoted sangen
                            if (musicrequests[i].Upvotes[j].Equals(musicrequestFromApp.UserId))
                            {
                                throw new APIException(StatusCodes.Status302Found);
                            }
                        }

                        //Går alle Downvotes på den enkle allerede eksiterende musicrequest igennem
                        for (int k = 0; k < musicrequests[i].Downvotes.Count; k++)
                        {
                            //Hvis brugeren allerede har downvoted sangen
                            if (musicrequests[i].Downvotes[k].Equals(musicrequestFromApp.UserId))
                            {
                                //Brugerens downvote bliver fjernet fra musicrequesten
                                RemoveDownvoteMusicrequest(musicrequests[i].Id, musicrequestFromApp.UserId);

                                //Brugeren upvoter musicrequesten
                                UpvoteMusicrequest(musicrequests[i].Id, musicrequestFromApp.UserId);
                                LiveRequest liverequest = new LiveRequest(musicrequestFromApp.Track, musicrequestFromApp.UserId, musicrequestFromApp.Downvotes, musicrequestFromApp.Upvotes);
                                AddLiveRequest(liverequest);
                                UpvoteLiveRequest(liverequest.Id, liverequest.UserId);
                                throw new APIException(StatusCodes.Status202Accepted);
                            }
                        }

                        //Brugeren upvoter musicrequesten
                        UpvoteMusicrequest(musicrequests[i].Id, musicrequestFromApp.UserId);
                        LiveRequest liverequest2 = new LiveRequest(musicrequestFromApp.Track, musicrequestFromApp.UserId, musicrequestFromApp.Downvotes, musicrequestFromApp.Upvotes);
                        AddLiveRequest(liverequest2);
                        UpvoteLiveRequest(liverequest2.Id, liverequest2.UserId);
                        throw new APIException(StatusCodes.Status201Created);
                    }
                }

                if (!isRequestedBefore)
                {
                    //Opreter en ny musicrequest, da den ikke allerede eksitere
                    Musicrequest musicrequest = new Musicrequest(musicrequestFromApp.Track, musicrequestFromApp.UserId, musicrequestFromApp.Downvotes, musicrequestFromApp.Upvotes);
                    LiveRequest  liverequest1 = new LiveRequest(musicrequestFromApp.Track, musicrequestFromApp.UserId, musicrequestFromApp.Downvotes, musicrequestFromApp.Upvotes);
                    musicrequestDAO.Add(musicrequest);
                    UpvoteMusicrequest(musicrequest.Id, musicrequest.UserId);
                    AddLiveRequest(liverequest1);
                    UpvoteLiveRequest(liverequest1.Id, liverequest1.UserId);

                    //Bug fix
                    if (musicrequest.Upvotes.Count.Equals(2))
                    {
                        musicrequest.Upvotes.RemoveAt(1);
                    }
                    if (liverequest1.Upvotes.Count.Equals(2))
                    {
                        liverequest1.Upvotes.RemoveAt(1);
                    }
                }
            }
            else
            {
                throw new APIException(StatusCodes.Status422UnprocessableEntity);
            }
        }
 public void UpvoteLiveRequest(int id, int userid)
 {
     liveRequestDAO.AddUpvote(id, ControllerRegistry.GetUserController().GetUser(userid));
 }