/// <summary>
 /// Removes an item from the list of media items.
 /// </summary>
 /// <param name="oldMedia">An item form the list of media items you want to delete.</param>
 public void RemoveMedia(DataModel.Media oldMedia)
 {
     if (Mapper.DeleteMedia(oldMedia))
     {
         List.Remove(oldMedia);
     }
 }
Exemplo n.º 2
0
        public DataModel.Media AddMedia(DataModel.Media newMedia)
        {
            string addQuery;

            if (newMedia.File == null)
            {
                addQuery = "INSERT INTO Song (Title, Singer) VALUES ('" + newMedia.Title + "', '" + ((Song)newMedia).Singer + "');"
                           + " SELECT CAST(scope_identity() AS int);";
            }
            else
            {
                addQuery = "INSERT INTO Song (Title, Singer, File) VALUES ('" + newMedia.Title + "', '" + ((Song)newMedia).Singer + "', '"
                           + "0x" + BitConverter.ToString(newMedia.File).Replace("-", "") + "');"
                           + " SELECT CAST(scope_identity() AS int);";
            }

            try
            {
                using (SqlConnection cn = MediaDB.GetConnection())
                {
                    using (SqlCommand cmd = new SqlCommand(addQuery, cn))
                    {
                        cn.Open();
                        newMedia.Id = (int)cmd.ExecuteScalar();
                    }
                }
            }
            catch (SqlException)
            {
                throw new SaveMediaFailedException();
            }
            return(newMedia);
        }
Exemplo n.º 3
0
        public bool UpdateMedia(DataModel.Media updateMedia)
        {
            int    updateCount = 0;
            string updateQuery;

            if (updateMedia.File == null)
            {
                updateQuery = "UPDATE Song SET Title = '" + updateMedia.Title + "', Singer = '" + ((Song)updateMedia).Singer + "' WHERE Id = " + updateMedia.Id;
            }
            else
            {
                updateQuery = "UPDATE Song SET Title = '" + updateMedia.Title + "', Singer = '" + ((Song)updateMedia).Singer + "', File = '"
                              + "0x" + BitConverter.ToString(updateMedia.File).Replace("-", "")
                              + "' WHERE Id = " + updateMedia.Id;
            }

            try
            {
                using (SqlConnection cn = MediaDB.GetConnection())
                {
                    using (SqlCommand cmd = new SqlCommand(updateQuery, cn))
                    {
                        cn.Open();
                        updateCount = cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException)
            {
                throw new UpdateMediaFailedException();
            }
            return(updateCount > 0);
        }
 /// <summary>
 /// Sets the property Selected to an item from the list of media items.
 /// </summary>
 /// <param name="newSelected">An item from the list of media items you want to set as selected.</param>
 public void ChangeSelected(DataModel.Media newSelected)
 {
     if (Mapper.UpdateMedia(newSelected))
     {
         Selected = newSelected;
     }
 }
 /// <summary>
 /// Removes an item from the list of media items.
 /// </summary>
 /// <param name="oldMedia">An item from the list of media items you want to delete.</param>
 public void RemoveMedia(DataModel.Media oldMedia)
 {
     ClearSelected();
     //List.Remove(oldMedia);
     _mediaMapper.DeleteMedia(oldMedia);
     this.InitializeData();
 }
 /// <summary>
 /// Adds an item to the list of media items.
 /// </summary>
 /// <param name="newMedia">A new media item that you want to add to the list of media items.</param>
 public void AddMedia(DataModel.Media newMedia)
 {
     ClearSelected();
     //List.Add(newMedia);
     _mediaMapper.AddMedia(newMedia);
     this.InitializeData();
 }
 /// <summary>
 /// Sets the property Selected to an item from the list of media items.
 /// </summary>
 /// <param name="newSelected">An item from the list of media items you want to set as selected.</param>
 public void ChangeSelected(DataModel.Media newSelected)
 {
     if (List.Contains(newSelected))
     {
         Selected = newSelected;
     }
 }
Exemplo n.º 8
0
        public bool DeleteMedia(DataModel.Media oldMedia)
        {
            int    deleteCount = 0;
            string deleteQuery = "DELETE FROM Song WHERE Id = " + oldMedia.Id;

            try
            {
                using (SqlConnection cn = MediaDB.GetConnection())
                {
                    using (SqlCommand cmd = new SqlCommand(deleteQuery, cn))
                    {
                        cn.Open();
                        deleteCount = cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException)
            {
                throw new RemoveMediaFailedException();
            }
            return(deleteCount > 0);
        }
 /// <summary>
 /// Adds an item to the list of media items.
 /// </summary>
 /// <param name="newMedia">A new media item that you want to add to the list of media items.</param>
 public void AddMedia(DataModel.Media newMedia)
 {
     List.Add(Mapper.AddMedia(newMedia));
 }
 /// <summary>
 /// Sets the property Selected to default (null).
 /// </summary>
 public void ClearSelected()
 {
     Selected = null;
 }
Exemplo n.º 11
0
 public void RemoveMedia(DataModel.Media oldMedia)
 {
     playlist.Remove(oldMedia);
 }
Exemplo n.º 12
0
 public void AddMedia(DataModel.Media newMedia)
 {
     playlist.Add(newMedia);
 }
 /// <summary>
 /// Updates an item in the list of media items.
 /// </summary>
 /// <param name="updateMedia">An item from the list of media items you want to update.</param>
 public void UpdateMedia(DataModel.Media updateMedia)
 {
     ClearSelected();
     _mediaMapper.UpdateMedia(updateMedia);
     this.InitializeData();
 }
 /// <summary>
 /// Removes an item from the list of media items.
 /// </summary>
 /// <param name="oldMedia">An item form the list of media items you want to delete.</param>
 public void RemoveMedia(DataModel.Media oldMedia)
 {
     ClearSelected();
     List.Remove(oldMedia);
 }
 /// <summary>
 /// Adds an item to the list of media items.
 /// </summary>
 /// <param name="newMedia">A new media item that you want to add to the list of media items.</param>
 public void AddMedia(DataModel.Media newMedia)
 {
     ClearSelected();
     List.Add(newMedia);
 }