Beispiel #1
0
        /// <summary>
        /// Event fired when data is bound to the details view
        /// In this event, the checkbox values are loaded from db and updated in the view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dvwWine_DataBound(object sender, EventArgs e)
        {
            CheckBoxList cblAttributes = (CheckBoxList)dvwWine.FindControl("cblAttributes");
            if (cblAttributes != null && dvwWine.DataItem != null)
            {
                //get current Id
                int currentId = ((DataLayer.Wine)dvwWine.DataItem).Id;
                //Create the WineToWineAttribute repository
                BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute> attributeAssignmentRepository =
                    new BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute>();
                //retrieve all attribute assignments
                IEnumerable<DataLayer.WineToWineAttribute> attributeAssignments =
                    attributeAssignmentRepository.GetItems().Where(cc => cc.FK_Wine == currentId);
                //set the checkboxes
                cblAttributes.Items.SetSelectedItems(attributeAssignments.Select(cc => cc.FK_WineAttribute).ToList());

            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates all attribute assigments found in the given checkboxlist for wine with id = wineID
        /// </summary>
        /// <param name="cblAttributes"></param>
        /// <param name="wineId"></param>
        private void SetAttributeAssignments(CheckBoxList cblAttributes, int wineId)
        {
            BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute> attributeAssignmentRepository = new BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute>();

            foreach (var selectedAttribute in cblAttributes.Items.GetSelectedItems())
            {
                DataLayer.WineToWineAttribute newAttribute = new DataLayer.WineToWineAttribute();
                newAttribute.FK_Wine = wineId;// Convert.ToInt32(e.Keys[0]);
                newAttribute.FK_WineAttribute = Convert.ToInt32(selectedAttribute.Value);
                attributeAssignmentRepository.CreateItem(newAttribute);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Deletes any attributes assignments of the wine with id = wineID
        /// </summary>
        /// <param name="wineId"></param>
        private void ClearAttributeAssignments(int wineId)
        {
            BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute> attributeAssignmentRepository = new BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute>();

            IEnumerable<DataLayer.WineToWineAttribute> currentAttributes =
                new BusinessLogicLayer.Repository<DataLayer.WineToWineAttribute>().GetItems().Where(cc => cc.FK_Wine == wineId);

            foreach (var currentAttribute in currentAttributes)
            {
                attributeAssignmentRepository.DeleteItem(currentAttribute);
            }
        }