コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["checkout"] != null)
        {
            shopCart = (Dictionary <string, int>)Session["checkout"];
        }
        else
        {
            shopCart.Add("Apples", 0);
            shopCart.Add("Shreddies", 0);
            shopCart.Add("Bread", 0);
            shopCart.Add("Eggs", 0);
            shopCart.Add("Milk", 0);
            shopCart.Add("Butter", 0);
            shopCart.Add("Cake", 0);
            shopCart.Add("Tomatoes", 0);
        }

        if (!Page.IsPostBack)
        {
            CheckedList.DataTextField = "Key";
            CheckedList.DataSource    = shopCart;
            CheckedList.DataBind();
        }

        Label1.Text = "There are " + shopCart.Sum(item => item.Value) + " items in your cart";
    }
コード例 #2
0
        private CheckedList <Artist> GetArtistCheckBoxes()
        {
            var artists   = artistRepository.GetAllArtists();
            var checkList = new CheckedList <Artist>();

            foreach (var artist in artists)
            {
                checkList.Add(artist, false);
            }
            return(checkList);
        }
コード例 #3
0
        /// <summary>
        /// Band Id
        /// </summary>
        /// <param name="id">Band Id</param>
        /// <returns></returns>
        private CheckedList <Artist> GetArtistCheckBoxes(int id)
        {
            var artists   = artistRepository.GetAllArtists();
            var checkList = new CheckedList <Artist>();

            foreach (var artist in artists)
            {
                bool isChecked = artist.Bands == null ? false : artist.Bands.Any(x => x.Id == id);
                checkList.Add(artist, isChecked);
            }
            return(checkList);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">BandId</param>
        /// <param name="checkedList"></param>
        public void UpdateArtists(int id, CheckedList <Artist> checkedList)
        {
            var band = context.Bands.Include(x => x.Artists).Single(x => x.Id == id);

            foreach (var artist in checkedList)
            {
                //There is no artist registered with this band, so add it
                if (artist.Value == true && !DoesThisBandHaveThisArtist(artist.Key.Id, band))
                {
                    if (band.Artists == null)
                    {
                        band.Artists = new List <Artist>();
                    }
                    band.Artists.Add(context.Artists.Find(artist.Key.Id));
                }
                else if (artist.Value == false && DoesThisBandHaveThisArtist(artist.Key.Id, band))
                {
                    band.Artists.Remove(context.Artists.Find(artist.Key.Id));
                }
            }
            Save();
        }
コード例 #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="id">BandId</param>
 /// <param name="checkedList"></param>
 public void UpdateArtists(int id, CheckedList<Artist> checkedList)
 {
     var band = context.Bands.Include(x=>x.Artists).Single(x=>x.Id == id);
     foreach (var artist in checkedList)
     {
         //There is no artist registered with this band, so add it
         if (artist.Value == true && !DoesThisBandHaveThisArtist(artist.Key.Id,band))
         {
             if (band.Artists == null)
             {
                 band.Artists = new List<Artist>();
             }
             band.Artists.Add(context.Artists.Find(artist.Key.Id));
         }
         else if (artist.Value == false && DoesThisBandHaveThisArtist(artist.Key.Id, band))
             band.Artists.Remove(context.Artists.Find(artist.Key.Id));
     }
     Save();
 }
コード例 #6
0
 /// <summary>
 /// Band Id
 /// </summary>
 /// <param name="id">Band Id</param>
 /// <returns></returns>
 private CheckedList<Artist> GetArtistCheckBoxes(int id)
 {
     var artists = artistRepository.GetAllArtists();
     var checkList = new CheckedList<Artist>();
     foreach (var artist in artists)
     {
         bool isChecked = artist.Bands == null ? false : artist.Bands.Any(x => x.Id == id);
         checkList.Add(artist, isChecked);
     }
     return checkList;
 }
コード例 #7
0
 private CheckedList<Artist> GetArtistCheckBoxes()
 {
     var artists = artistRepository.GetAllArtists();
     var checkList = new CheckedList<Artist>();
     foreach (var artist in artists)
     {
         checkList.Add(artist, false);
     }
     return checkList;
 }