public ActionResult AddNewChart(string ChartName, string ChartDesc, string ChartDate, int UserID, int PlaylistID)
 {
     if (Session["Roles"] != null && Session["Roles"].Equals("Admin"))
     {
         hypster_tv_DAL.chartsManager chartManager = new hypster_tv_DAL.chartsManager();
         hypster_tv_DAL.Chart         chart_add    = new hypster_tv_DAL.Chart();
         chart_add.Chart_Name        = ChartName;
         chart_add.Chart_Desc        = ChartDesc;
         chart_add.Chart_Date        = ChartDate;
         chart_add.Chart_User_ID     = UserID;
         chart_add.Chart_Playlist_ID = PlaylistID;
         chart_add.Chart_GUID        = chart_add.Chart_Name.Replace("/", "").Replace("\\", "").Replace("&", "").Replace("+", "").Replace(" ", "-").Replace("?", "").Replace("!", "").Replace("*", "").Replace("$", "").Replace("\"", "").Replace("'", "").Replace("{", "").Replace("}", "").Replace(")", "").Replace("(", "").Replace("[", "").Replace("]", "").Replace("|", "").Replace(".", "").Replace(",", "").Replace(":", "").Replace(";", "");
         hypster_tv_DAL.Chart check_chart = new hypster_tv_DAL.Chart();
         check_chart = chartManager.GetChartByGuid(chart_add.Chart_GUID);
         if (check_chart.Chart_ID != 0)
         {
             Random rand = new Random();
             chart_add.Chart_GUID += "_" + rand.Next(1, 200000).ToString();
         }
         chartManager.AddNewChart(chart_add);
         return(RedirectPermanent("/WebsiteManagement/manageCharts"));
     }
     else
     {
         return(RedirectPermanent("/home/"));
     }
 }
        public ActionResult AddNewCloneChart(string ChartGuid, string ChartName, string ChartDesc, string ChartDate, int UserID, string existingChartGuid)
        {
            if (Session["Roles"] != null && Session["Roles"].Equals("Admin"))
            {
                hypster_tv_DAL.chartsManager      chartManager    = new hypster_tv_DAL.chartsManager();
                hypster_tv_DAL.playlistManagement playlistManager = new hypster_tv_DAL.playlistManagement();
                if (chartManager.GetChartByGuid(ChartGuid).Chart_ID == 0)
                {
                    //create cloned chart
                    hypster_tv_DAL.Chart newClonedChart = new hypster_tv_DAL.Chart();
                    newClonedChart.Chart_GUID    = ChartGuid;
                    newClonedChart.Chart_Name    = ChartName;
                    newClonedChart.Chart_Desc    = ChartDesc;
                    newClonedChart.Chart_Date    = ChartDate;
                    newClonedChart.Chart_User_ID = UserID;
                    //get existing chart
                    hypster_tv_DAL.Chart existing_chart = new hypster_tv_DAL.Chart();
                    existing_chart = chartManager.GetChartByGuid(existingChartGuid);
                    //get existing songs for cloning
                    List <hypster_tv_DAL.PlaylistData_Song> existing_songs = new List <hypster_tv_DAL.PlaylistData_Song>();
                    existing_songs = playlistManager.GetSongsForPlayList((int)existing_chart.Chart_User_ID, (int)existing_chart.Chart_Playlist_ID);
                    //clone playlist
                    hypster_tv_DAL.Playlist existing_playlist = new hypster_tv_DAL.Playlist();
                    existing_playlist = playlistManager.GetUserPlaylistById((int)existing_chart.Chart_User_ID, (int)existing_chart.Chart_Playlist_ID);
                    hypster_tv_DAL.Playlist new_playlist = new hypster_tv_DAL.Playlist();
                    new_playlist.create_time        = 0;
                    new_playlist.is_artist_playlist = false;
                    new_playlist.name        = existing_playlist.name + " CLONE";
                    new_playlist.update_time = 0;
                    new_playlist.userid      = existing_playlist.userid;
                    new_playlist.ViewsNum    = 0;
                    new_playlist.Likes       = 0;
                    int new_playlist_id = playlistManager.AddNewPlaylist(new_playlist);
                    //assign to chart new cloned playlist
                    newClonedChart.Chart_Playlist_ID = new_playlist_id;
                    //clone songs
                    List <hypster_tv_DAL.PlaylistData_Song> new_songs = new List <hypster_tv_DAL.PlaylistData_Song>();
                    hypster_tv_DAL.Hypster_Entities         hypDB     = new hypster_tv_DAL.Hypster_Entities();
                    foreach (var item in existing_songs)
                    {
                        hypster_tv_DAL.PlaylistData song = new hypster_tv_DAL.PlaylistData();
                        song.playlist_id = new_playlist_id;
                        song.userid      = new_playlist.userid;
                        song.sortid      = item.sortid;
                        song.songid      = (int)item.id;

                        hypDB.PlaylistDatas.AddObject(song);
                        hypDB.SaveChanges();
                    }
                    //add new cloned chart (after playlist cloned)
                    chartManager.AddNewChart(newClonedChart);
                }
                return(RedirectPermanent("/WebsiteManagement/manageCharts"));
            }
            else
            {
                return(RedirectPermanent("/home/"));
            }
        }