//INSERT- UPDATE - DELETE 
        public int Insert(string UserId, int TypeId, int ParentId, string Name, string Photo, string Description, string Status)
        {
            string Alias = module_obj.createTags(Name);
            using (MediaEntities dbContext = new MediaEntities())
            {
                dbContext.CommandTimeout = Settings.CommandTimeout;
                System.Nullable<Int32> ListOrder = (from u in dbContext.Media_Types select u.TypeId).DefaultIfEmpty(0).Max() + 1;

                Media_Topics topic_obj = new Media_Topics();
                topic_obj.TypeId = TypeId;
                topic_obj.Name = Name;
                topic_obj.Alias = Alias;
                topic_obj.ParentId = ParentId;
                topic_obj.ListOrder = (ListOrder == null ? 1 : ListOrder);
                topic_obj.Photo = Photo;
                topic_obj.Description = Description;
                topic_obj.IPLog = IP;
                topic_obj.CreatedByUserId = new Guid(UserId);
                topic_obj.CreatedOnDate = System.DateTime.Now;
                topic_obj.Status = Status;
                dbContext.AddToMedia_Topics(topic_obj);
                int i = dbContext.SaveChanges();
                return i;
            }
        }
 public int Update(int PlayListId,int TypeId, string UserId, string PlayListName, string FrontImage, string MainImage, string Description, string Status)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         string Alias = StringUtils.GenerateFriendlyString(PlayListName);
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_PlayLists entity = dbContext.Media_PlayLists.Single(x => x.PlayListId == PlayListId);
         entity.TypeId = TypeId;
         entity.PlayListName = PlayListName;
         entity.Alias = Alias;
         entity.FrontImage = FrontImage;
         entity.MainImage = MainImage;
         entity.Description = Description;
         entity.IPModifiedLog = IP;
         entity.LastModifiedOnDate = System.DateTime.Now;
         entity.LastModifiedByUserId = new Guid(UserId);
         entity.Status = Status;
         int i = dbContext.SaveChanges();
         return i;
     }        
 }
        //INSERT- UPDATE - DELETE 
        public int Insert(string UserId, int TypeId, string PlayListName, string FrontImage, string MainImage, string Description, string Status)
        {
            using (MediaEntities dbContext = new MediaEntities())
            {
                string Alias = StringUtils.GenerateFriendlyString(PlayListName);
                dbContext.CommandTimeout = Settings.CommandTimeout;
                System.Nullable<Int32> SortOrder = (from u in dbContext.Media_PlayLists select u.SortOrder).DefaultIfEmpty(0).Max() + 1;

                Media_PlayLists entity = new Media_PlayLists();
                entity.TypeId = TypeId;
                entity.PlayListName = PlayListName;
                entity.Alias = Alias;
                entity.FrontImage = FrontImage;
                entity.MainImage = MainImage;
                entity.Description = Description;
                entity.SortOrder = (SortOrder == null ? 1 : SortOrder);
                entity.IPLog = IP;
                entity.CreatedOnDate = System.DateTime.Now;
                entity.CreatedByUserId = new Guid(UserId);
                entity.Status = Status;
                dbContext.AddToMedia_PlayLists(entity);
                int i  = dbContext.SaveChanges();
                return i;
            }
        }
 public int Update(int TypeId, string UserId, string TypeName, string TypeExt, string TypePath, string Description, string Status)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         //Media_Types type_obj = (from x in dbContext.Media_Types where x.TypeId == TypeId select x).First();
         Media_Types type_obj = dbContext.Media_Types.Single(x => x.TypeId == TypeId);
         type_obj.TypeName = TypeName;
         type_obj.TypeExt = TypeExt;
         type_obj.TypePath = TypePath;
         type_obj.Description = Description;
         type_obj.IPModifiedLog = IP;
         type_obj.ModifiedDate = System.DateTime.Now;
         type_obj.LastModifiedByUserId = new Guid(UserId);
         type_obj.Status = Status;
         int i = dbContext.SaveChanges();
         return i;
     }
 }
        //INSERT- UPDATE - DELETE 
        public int Insert(string UserId, string TypeName, string TypeExt, string TypePath, string Description, string Status)
        {
            using (MediaEntities dbContext = new MediaEntities())
            {
                dbContext.CommandTimeout = Settings.CommandTimeout;
                System.Nullable<Int32> ListOrder = (from u in dbContext.Media_Types select u.TypeId).DefaultIfEmpty(0).Max() + 1;

                Media_Types type_obj = new Media_Types();
                type_obj.TypeName = TypeName;
                type_obj.TypeExt = TypeExt;
                type_obj.TypePath = TypePath;
                type_obj.Description = Description;
                type_obj.CreatedByUserId = new Guid(UserId);
                type_obj.CreatedOnDate = System.DateTime.Now;                
                type_obj.IPLog = IP;
                type_obj.ListOrder = (ListOrder == null ? 1 : ListOrder);
                type_obj.Status = Status;
                dbContext.AddToMedia_Types(type_obj);
                int i  = dbContext.SaveChanges();
                return i;
            }
        }
 public int Delte(int TypeId)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         //Media_Types type_obj = (from x in dbContext.Media_Types where x.TypeId == TypeId select x).First();
         Media_Types type_obj = dbContext.Media_Types.Single(x => x.TypeId == TypeId);
         dbContext.DeleteObject(type_obj);
         int i = dbContext.SaveChanges();
         return i;
     }
 }
 public int Update(int AlbumId, string UserId, int TypeId, string AlbumName, string FrontImage, string MainImage, string Description, string Status)
 {
     int i =0;
     using (MediaEntities dbContext = new MediaEntities())
     {
         using (System.Transactions.TransactionScope transcope = new System.Transactions.TransactionScope())
         {
             //dbContext.CommandTimeout = Settings.CommandTimeout;
             dbContext.Connection.Open();                    
             string Alias = StringUtils.GenerateFriendlyString(AlbumName);
             Media_Albums entity = dbContext.Media_Albums.Single(x => x.AlbumId == AlbumId);
             entity.TypeId = TypeId;
             entity.AlbumName = AlbumName;
             entity.Alias = Alias;
             entity.FrontImage = FrontImage;
             entity.MainImage = MainImage;
             entity.Description = Description;
             entity.IPLastUpdate = IP;
             entity.LastModifiedByUserId = new Guid(UserId);
             entity.LastModifiedOnDate = System.DateTime.Now;
             entity.Status = Status;
             i = dbContext.SaveChanges();
             dbContext.Connection.Close();
             transcope.Complete();
         }   
     }
     return i;
 }
 public int Update(int ComposerId, string UserId, string ComposerName, string FrontImage, string MainImage, string Description, string Status)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         string Alias = StringUtils.GenerateFriendlyString(ComposerName);
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_Composers composers_obj = dbContext.Media_Composers.Single(x => x.ComposerId == ComposerId);
         composers_obj.ComposerName = ComposerName;
         composers_obj.Alias = Alias;
         composers_obj.FrontImage = FrontImage;
         composers_obj.MainImage = MainImage;
         composers_obj.Description = Description;
         composers_obj.IPModifiedLog = IP;
         composers_obj.LastModifiedOnDate = System.DateTime.Now;
         composers_obj.LastModifiedByUserId = new Guid(UserId);
         composers_obj.Status = Status;
         int i = dbContext.SaveChanges();
         return i;
     }        
 }
 public int Update(int ArtistId, string UserId, string ArtistName, string FrontImage, string MainImage, string Description, string Status)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         string Alias = StringUtils.GenerateFriendlyString(ArtistName);
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_Artists artists_obj = dbContext.Media_Artists.Single(x => x.ArtistId == ArtistId);
         artists_obj.ArtistName = ArtistName;
         artists_obj.Alias = Alias;
         artists_obj.FrontImage = FrontImage;
         artists_obj.MainImage = MainImage;
         artists_obj.Description = Description;
         artists_obj.IPLastUpdate = IP;
         artists_obj.LastModifiedDate = System.DateTime.Now;
         artists_obj.LastModifiedByUserId = new Guid(UserId);
         artists_obj.Status = Status;
         int i = dbContext.SaveChanges();
         return i;
     }        
 }
 public int Update(string UserId, int TypeId, int TopicId, int ParentId, string Name, string Photo, string Description, string Status)
 {
     string Alias = module_obj.createTags(Name);
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_Topics topic_obj = dbContext.Media_Topics.Single(x => x.TopicId == TopicId);
         topic_obj.TypeId = TypeId;
         topic_obj.TopicId = TopicId;
         topic_obj.Name = Name;
         topic_obj.Alias = Alias;
         topic_obj.ParentId = ParentId;
         topic_obj.Photo = Photo;
         topic_obj.Description = Description;
         topic_obj.IPLog = IP;
         topic_obj.CreatedByUserId = new Guid(UserId);
         topic_obj.CreatedOnDate = System.DateTime.Now;
         topic_obj.Status = Status;              
         int i = dbContext.SaveChanges();
         return i;
     }
 }
        public int Delete(string UserId, int Idx, string Dir_Path)
        {
            using (MediaEntities dbContext = new MediaEntities())
            {
                dbContext.CommandTimeout = Settings.CommandTimeout;
                string filename = (from x in dbContext.Media_Topics where x.TopicId == Idx select x.Photo).SingleOrDefault();
                if (filename != null && filename != string.Empty)
                    module_obj.deleteFile(filename, Dir_Path);

                //Media_Topics topic_obj = (from x in dbContext.Media_Topics where x.TopicId == Idx select x).First();
                Media_Topics topic_obj = dbContext.Media_Topics.Single(x => x.TopicId == Idx);
                dbContext.DeleteObject(topic_obj);
                int i = dbContext.SaveChanges();
                return i;
            }
        } 
 public int UpdateStatus(string UserId, int TopicId, string Status)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_Topics topic_obj = dbContext.Media_Topics.Single(x => x.TopicId == TopicId);
         topic_obj.TopicId = TopicId;
         topic_obj.Status = Status;
         topic_obj.LastModifiedByUserId = new Guid(UserId);
         topic_obj.LastModifiedDate = System.DateTime.Now;
         int i = dbContext.SaveChanges();
         return i;
     }
 }
 public int UpdateSortKey(string UserId, int AlbumId, int SortKey)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_Albums album_obj = dbContext.Media_Albums.Single(x => x.AlbumId == AlbumId);
         album_obj.IPLastUpdate = IP;
         album_obj.LastModifiedByUserId = new Guid(UserId);
         album_obj.LastModifiedOnDate = System.DateTime.Now;
         album_obj.SortKey = SortKey;
         int i = dbContext.SaveChanges();
         return i;
     }
 }
 public int UpdateSortKey(string UserId, int PlayListId, int SortOrder)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_PlayLists playLists_obj = dbContext.Media_PlayLists.Single(x => x.PlayListId == PlayListId);
         playLists_obj.IPModifiedLog = IP;
         playLists_obj.LastModifiedOnDate = System.DateTime.Now;
         playLists_obj.LastModifiedByUserId = new Guid(UserId);
         playLists_obj.SortOrder = SortOrder;
         int i = dbContext.SaveChanges();
         return i;
     }
 }
 public int UpdateSortKey(string UserId, int ArtistId, int ListOrder)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_Artists artists_obj = dbContext.Media_Artists.Single(x => x.ArtistId == ArtistId);
         artists_obj.IPLastUpdate = IP;
         artists_obj.LastModifiedByUserId = new Guid(UserId);
         artists_obj.LastModifiedDate = System.DateTime.Now;
         artists_obj.ListOrder = ListOrder;
         int i = dbContext.SaveChanges();
         return i;
     }
 }
        //INSERT- UPDATE - DELETE 
        public int Insert(string UserId, string ComposerName, string FrontImage, string MainImage, string Description, string Status)
        {
            using (MediaEntities dbContext = new MediaEntities())
            {
                string Alias = StringUtils.GenerateFriendlyString(ComposerName);
                dbContext.CommandTimeout = Settings.CommandTimeout;
                System.Nullable<Int32> ListOrder = (from u in dbContext.Media_Composers select u.ListOrder).DefaultIfEmpty(0).Max() + 1;

                Media_Composers composers_obj = new Media_Composers();
                composers_obj.ComposerName = ComposerName;
                composers_obj.Alias = Alias;
                composers_obj.FrontImage = FrontImage;
                composers_obj.MainImage = MainImage;
                composers_obj.Description = Description;
                composers_obj.ListOrder = (ListOrder == null ? 1 : ListOrder);
                composers_obj.IPLog = IP;    
                composers_obj.CreatedOnDate = System.DateTime.Now;
                composers_obj.CreatedByUserId = new Guid(UserId);            
                composers_obj.Status = Status;
                dbContext.AddToMedia_Composers(composers_obj);
                int i  = dbContext.SaveChanges();
                return i;
            }
        }
        public int UpdateSortKey(string UserId, int TypeId, int ListOrder)
        {
            using (MediaEntities dbContext = new MediaEntities())
            {
                dbContext.CommandTimeout = Settings.CommandTimeout;

                Media_Types type_obj = dbContext.Media_Types.Single(x => x.TypeId == TypeId);
                type_obj.TypeId = TypeId;
                type_obj.ListOrder = ListOrder;
                type_obj.LastModifiedByUserId = new Guid(UserId);
                type_obj.ModifiedDate = System.DateTime.Now;
                int i = dbContext.SaveChanges();
                return i;
            }
        }
 public int UpdateSortKey(string UserId, int ComposerId, int ListOrder)
 {
     using (MediaEntities dbContext = new MediaEntities())
     {
         dbContext.CommandTimeout = Settings.CommandTimeout;
         Media_Composers composers_obj = dbContext.Media_Composers.Single(x => x.ComposerId == ComposerId);
         composers_obj.IPModifiedLog = IP;
         composers_obj.LastModifiedByUserId = new Guid(UserId);
         composers_obj.LastModifiedOnDate = System.DateTime.Now;
         composers_obj.ListOrder = ListOrder;
         int i = dbContext.SaveChanges();
         return i;
     }
 }
        //INSERT- UPDATE - DELETE 
        public int Insert(string UserId, int TypeId, string AlbumName, string FrontImage, string MainImage, string Description, string Status)
        {
            int returnValue = 0;
            using (MediaEntities dbContext = new MediaEntities())
            {
                using (System.Transactions.TransactionScope transcope = new System.Transactions.TransactionScope())
                {
                    string Alias = StringUtils.GenerateFriendlyString(AlbumName);
                    dbContext.CommandTimeout = Settings.CommandTimeout;
                    System.Nullable<Int32> SortKey = (from u in dbContext.Media_Albums select u.SortKey).DefaultIfEmpty(0).Max() + 1;

                    Media_Albums entity = new Media_Albums();
                    entity.TypeId = TypeId;
                    entity.AlbumName = AlbumName;
                    entity.Alias = Alias;
                    entity.FrontImage = FrontImage;
                    entity.MainImage = MainImage;
                    entity.Description = Description;
                    entity.SortKey = (SortKey == null ? 1 : SortKey);
                    entity.IPLog = IP;
                    entity.CreatedByUserId = new Guid(UserId);
                    entity.CreatedOnDate = System.DateTime.Now;
                    entity.Status = Status;

                    dbContext.AddToMedia_Albums(entity);
                    returnValue = dbContext.SaveChanges();
                    transcope.Complete();
                }                
            }
            return returnValue;
        }