/// <summary> /// Get list of all ComicstripBundle Comicstrips /// </summary> public List <ComicStrip> GetComicstrips(int id) { var cmd = "SELECT * FROM [dbo].[ComicstripBundleComicstrips] WHERE ComicstripBundle_Id = @Bundle"; using (var selectCmd = new SqlCommand(cmd, this.context)) { try { selectCmd.Parameters.AddWithValue("@Bundle", id); this.context.Open(); SqlDataAdapter reader = new SqlDataAdapter(selectCmd); DataTable table = new DataTable(); reader.Fill(table); this.context.Close(); if (table.Rows.Count > 0) { //List<ComicStrip> comicstrips = new ComicStripRepository(this.context).GetAll(); //return table.AsEnumerable().Select(x => comicstrips.Where(y => y.ID == x.Field<int>("Comicstrip_Id")).Single()).ToList<ComicStrip>(); ComicStripRepository sRepoo = new ComicStripRepository(this.context); return(table.AsEnumerable().Select(x => sRepoo.GetByID(x.Field <int>("Comicstrip_Id"))).ToList <ComicStrip>()); } } catch (Exception) { throw new Exception("Something went wrong while retrieving the bundle strips"); } } return(new List <ComicStrip>()); }
/// <summary> /// Get list of all Delivery Items /// </summary> public List <DeliveryItem> GetItems(int id) { var cmd = "SELECT * FROM [dbo].[DeliveryItems] WHERE Delivery_Id = @Delivery"; using (var selectCmd = new SqlCommand(cmd, this.context)) { try { selectCmd.Parameters.AddWithValue("@Delivery", id); this.context.Open(); SqlDataAdapter reader = new SqlDataAdapter(selectCmd); DataTable table = new DataTable(); reader.Fill(table); this.context.Close(); if (table.Rows.Count > 0) { ComicStripRepository sRepoo = new ComicStripRepository(this.context); return(table.AsEnumerable().Select(x => new DeliveryItem(x.Field <int>("Id"), sRepoo.GetByID(x.Field <int>("Comicstrip_Id")), x.Field <int>("Quantity"))).ToList <DeliveryItem>()); } } catch (Exception) { throw new Exception("Something went wrong while retrieving the delivery items"); } } return(new List <DeliveryItem>()); }