Esempio n. 1
0
        private void AddRow(ComicstripBundle bundle)
        {
            DataRow row = this.Table.NewRow();

            row[0] = bundle.ID;
            row[1] = bundle.Titel;
            row[2] = bundle.Publisher.Name;
            row[3] = string.Join(",", bundle.Comicstrips.Select(x => x.ID));
            this.Table.Rows.Add(row);
        }
 /// <summary>
 /// Update existing ComicstripBundle
 /// </summary>
 public void Update(ComicstripBundle b)
 {
     if (!uow.ComicstripBundles.Exist(b, /* Ignore Id Search */ true))
     {
         throw new ExistException("comicstrip bundle");
     }
     try
     {
         uow.ComicstripBundles.Update(b);
     }
     catch (Exception) { throw new UpdateException("comicstrip bundle"); }
 }
 /// <summary>
 /// Check if ComicstripBundle exist
 /// </summary>
 public bool Exist(ComicstripBundle b, bool ignoreId = false)
 {
     try
     {
         SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM [dbo].[ComicstripBundles] WHERE LOWER(Title) = @Title OR Id = @Id", this.context);
         cmd.Parameters.AddWithValue("@Title", b.Titel.ToLower());
         cmd.Parameters.AddWithValue("@Id", (!ignoreId) ? b.ID : -1);
         context.Open();
         int count = (int)cmd.ExecuteScalar();
         context.Close();
         return(count > 0);
     }
     catch (Exception) { throw new QueryException(); }
 }
 /// <summary>
 /// Update existing ComicstripBundle
 /// </summary>
 public void Update(ComicstripBundle b)
 {
     try
     {
         SqlCommand cmd = new SqlCommand("UPDATE [dbo].[ComicstripBundles] SET Title = @Title, Publisher_Id = @Publisher WHERE Id = @Id", this.context);
         cmd.Parameters.AddWithValue("@Titlel", b.Titel);
         cmd.Parameters.AddWithValue("@Publisher", b.Publisher.ID);
         cmd.Parameters.AddWithValue("@Id", b.ID);
         context.Open();
         cmd.ExecuteNonQuery();
         context.Close();
     }
     catch (Exception) { throw new QueryException(); }
 }
 /// <summary>
 /// Add a new ComicstripBundle
 /// </summary>
 public ComicstripBundle Add(ComicstripBundle b)
 {
     // Check if comicstrip  bundle exists
     if (uow.ComicstripBundles.Exist(b))
     {
         throw new ExistException("comicstrip bundle");
     }
     try
     {
         // Add comicstrip bundle and return object with generated id
         return(uow.ComicstripBundles.Add(b));
     }
     catch (Exception) { throw new AddException("comicstrip bundle"); }
 }
        /// <summary>
        /// Add a new ComicStrip
        /// </summary>
        public ComicstripBundle Add(ComicstripBundle b)
        {
            int id  = -1;
            var cmd = "INSERT INTO [dbo].[ComicstripBundles] (Title,Publisher_Id) VALUES (@Title,@Publisher);SELECT CAST(scope_identity() AS int)";

            using (var insertCmd = new SqlCommand(cmd, this.context))
            {
                insertCmd.Parameters.AddWithValue("@Title", b.Titel);
                insertCmd.Parameters.AddWithValue("@Publisher", b.Publisher.ID);
                try
                {
                    context.Open();
                    id = (int)insertCmd.ExecuteScalar();
                    context.Close();
                }
                catch (Exception) { throw new InsertException(); }
            }
            if (id < 0)
            {
                throw new ComicstripBundleAddException();
            }
            cmd = "INSERT INTO [dbo].[ComicstripBundleComicstrips] (ComicstripBundle_Id,Comicstrip_Id) VALUES (@Bundle,@Strip)";
            foreach (ComicStrip s in b.Comicstrips)
            {
                using (var insertCmd = new SqlCommand(cmd, this.context))
                {
                    insertCmd.Parameters.AddWithValue("@Bundle", id);
                    insertCmd.Parameters.AddWithValue("@Strip", s.ID);
                    try
                    {
                        context.Open();
                        insertCmd.ExecuteNonQuery();
                        context.Close();
                    }
                    catch (Exception) { throw new InsertException(); }
                }
            }
            return(new ComicstripBundle(id, b.Titel, b.Comicstrips, b.Publisher));
        }
 /// <summary>
 /// Check if ComicstripBundle exist
 /// </summary>
 public bool Exist(ComicstripBundle b, bool ignoreId = false)
 {
     return(uow.ComicstripBundles.Exist(b, ignoreId));
 }
Esempio n. 8
0
 public void AddBundle(ComicstripBundle bundle)
 {
     this.ComicstripBundles.Add(bundle);
     AddRow(bundle);
 }