public bool CopyProduct(String ProductID, String CopyCode, String CopyName)
        {
            bool ret = false;
            try
            {
                ProductClass productdata = new ProductClass();

                productdata.Code = CopyCode;
                productdata.Note = CopyName;
                
                db.ProductClass.Add(productdata);
                db.SaveChanges();
                List<int> oldIIDList = new List<int>();
                List<int> nweIIDList = new List<int>();
                int newPID = db.ProductClass.AsEnumerable().Where(x => x.Code == CopyCode).Select(x => x.ProductClassID).First();
                int pID = Int32.Parse(ProductID);
                var qry = db.ItemClass.Where(x => x.ProductClassID == pID);
                foreach (ItemClass i in qry)
                {
                    int ID = db.ItemClass.AsEnumerable().Select(x => x.ItemClassID).DefaultIfEmpty(0).Max(x => x) + 1;
                    ItemClass itemdata = new ItemClass();

                    itemdata.Code = i.Code;
                    itemdata.Note = i.Note;
                    itemdata.ProductClassID = newPID;
                    itemdata.ItemClassID = ID;

                    db.ItemClass.Add(itemdata);
                    //db.SaveChanges();
                    //int newIID = db.ItemClass.AsEnumerable().Where(x => x.Code == CopyCode && x.ProductClassID == newPID).Select(x => x.ItemClassID).First();
                    //nweIIDList.Add(ID);
                    oldIIDList.Add(i.ItemClassID);
                }
                db.SaveChanges();
                var qry3 = db.ItemClass.Where(x => x.ProductClassID == newPID).OrderBy(x=>x.ItemClassID);
                foreach (ItemClass i in qry3)
                {
                    nweIIDList.Add(i.ItemClassID);
                }

                
                for (int i = 0; i < oldIIDList.Count; i++)
                {
                    int iid = oldIIDList[i];
                    var qry2 = db.QuestionClass.Where(x => x.ItemClassID == iid);
                    foreach (QuestionClass q in qry2)
                    {
                        QuestionClass questiondata = new QuestionClass();

                        questiondata.Code = q.Code;
                        questiondata.Note = q.Note;
                        questiondata.ItemClassID = nweIIDList[i];
                        questiondata.QuestionGrade = q.QuestionGrade;
                        questiondata.QuestionServiceHours = q.QuestionServiceHours;

                        db.QuestionClass.Add(questiondata);
                        
                    }
                    db.SaveChanges();
                }
                //db.SaveChanges();

                
                ret = true;
            }
            catch
            {
                ret = false;
            }
            return ret;

        }
        public bool CreateProduct(ViewModels.ProductClassViewModel productClassViewModel)
        {
            bool ret = false;
            try
            {
                ProductClass productdata = new ProductClass();

                productdata.Code = productClassViewModel.Code;
                productdata.Note = productClassViewModel.Name;

                db.ProductClass.Add(productdata);
                db.SaveChanges();

                ret = true;
            }
            catch
            {
            }
            return ret;
        }