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"; }
private CheckedList <Artist> GetArtistCheckBoxes() { var artists = artistRepository.GetAllArtists(); var checkList = new CheckedList <Artist>(); foreach (var artist in artists) { checkList.Add(artist, false); } return(checkList); }
/// <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); }
/// <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(); }
/// <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(); }
/// <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; }
private CheckedList<Artist> GetArtistCheckBoxes() { var artists = artistRepository.GetAllArtists(); var checkList = new CheckedList<Artist>(); foreach (var artist in artists) { checkList.Add(artist, false); } return checkList; }