public bool Add(WorkoutCategoryDetailDTO entity)
        {
            WorkoutCategory workoutCategory = new WorkoutCategory();

            workoutCategory.Name = entity.Name;
            return(dao.Add(workoutCategory));
        }
        public void Update(WorkoutCategoryDetailDTO entity)
        {
            WorkoutCategory category = new WorkoutCategory();

            category.ID   = entity.ID;
            category.Name = entity.Name;
            dao.Update(category);
        }
        public List <WorkoutCategoryDetailDTO> GetCategories(string text)
        {
            List <WorkoutCategory>          categories = db.WorkoutCategories.Where(x => x.Name.Contains(text)).ToList();
            List <WorkoutCategoryDetailDTO> dtoList    = new List <WorkoutCategoryDetailDTO>();

            foreach (var item in categories)
            {
                WorkoutCategoryDetailDTO dto = new WorkoutCategoryDetailDTO();
                dto.ID   = item.ID;
                dto.Name = item.Name;
                dtoList.Add(dto);
            }
            return(dtoList);
        }
        public List <WorkoutCategoryDetailDTO> GetCategories()
        {
            List <WorkoutCategory>          categories = db.WorkoutCategories.ToList();
            List <WorkoutCategoryDetailDTO> dtoList    = new List <WorkoutCategoryDetailDTO>();

            foreach (var item in categories)
            {
                WorkoutCategoryDetailDTO dto = new WorkoutCategoryDetailDTO();
                dto.ID   = item.ID;
                dto.Name = item.Name;
                dtoList.Add(dto);
            }
            return(dtoList);
        }
        private void btnAddCat_Click(object sender, EventArgs e)
        {
            WorkoutCategoryDetailDTO detail = new WorkoutCategoryDetailDTO();

            if (txtName.Text == "")
            {
                MessageBox.Show("請輸入名稱");
            }
            else if (bll.IsCategoryExist(txtName.Text))
            {
                MessageBox.Show("該類別名稱已存在");
            }
            else
            {
                detail.Name = txtName.Text;
                if (bll.Add(detail))
                {
                    MessageBox.Show("已新增運動類別");
                    ShowWorkoutCat();

                    txtName.Clear();
                }
            }
        }