Esempio n. 1
0
        public UnitOfWork(String environment = "development")
        {
            setConnectionString(environment);
            connection = new SqlConnection(connectionString);

            Comicstrips       = new ComicStripRepository(connection);
            ComicstripBundles = new ComicstripBundleRepository(connection);
            Publishers        = new PublisherRepository(connection);
            Authors           = new AuthorRepository(connection);
            Deliveries        = new DeliveryRepository(connection);
            Orders            = new OrderRepository(connection);
        }
Esempio n. 2
0
 /// <summary>
 /// Get list of all Comicstrips
 /// </summary>
 public List <ComicStrip> GetAll()
 {
     try
     {
         SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[Comicstrips]", this.context);
         context.Open();
         SqlDataAdapter reader = new SqlDataAdapter(cmd);
         DataTable      table  = new DataTable();
         reader.Fill(table);
         context.Close();
         if (table.Rows.Count > 0)
         {
             List <Publisher> publishers = new PublisherRepository(this.context).GetAll();
             return(table.AsEnumerable().Select(s => new ComicStrip(s.Field <int>("Id"), s.Field <string>("Title"), (s.Field <int>("Serie_Id") > 0) ? GetSerie(s.Field <int>("Serie_Id")) : null, s.Field <int>("Number"), this.GetAuthors(s.Field <int>("Id")), publishers.Where(x => x.ID == s.Field <int>("Publisher_Id")).SingleOrDefault())).ToList <ComicStrip>());
         }
     }
     catch (Exception) { throw new QueryException(); }
     return(new List <ComicStrip>());
 }
Esempio n. 3
0
 /// <summary>
 /// Get a comicstrip by ID
 /// </summary>
 public ComicStrip GetByID(int id)
 {
     try
     {
         SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[Comicstrips] WHERE Id = @Id", this.context);
         cmd.Parameters.AddWithValue("@Id", id);
         context.Open();
         SqlDataAdapter reader = new SqlDataAdapter(cmd);
         DataTable      table  = new DataTable();
         reader.Fill(table);
         context.Close();
         if (table.Rows.Count > 0)
         {
             PublisherRepository pr = new PublisherRepository(this.context);
             return(table.AsEnumerable().Select(s => new ComicStrip(s.Field <int>("Id"), s.Field <string>("Title"), GetSerie(s.Field <int>("Serie_Id")), s.Field <int>("Number"), this.GetAuthors(s.Field <int>("Id")), pr.GetByID(s.Field <int>("Publisher_Id")))).Single <ComicStrip>());
         }
     }
     catch (Exception) { throw new QueryException(); }
     return(null);
 }