public List <Product> deleteSubCategory(int id, int adminid)
        {
            var           db = new DatabaseContext();
            SubCategories c  = db.SubCategories.FirstOrDefault(ca => ca.Id == id);

            db.SubCategories.Remove(c);
            try
            {
                db.SaveChanges(adminid);
            }
            catch (DbUpdateException ue)
            {
                writeToFile(ue);
                try
                {
                    return(db.Products.Where(sc => sc.SubCategoriesId == id).Select(p => new Product()
                    {
                        name = p.Name
                    }).ToList());
                }
                catch (Exception e)
                {
                    writeToFile(e);
                }
            }
            catch (Exception e)
            {
                writeToFile(e);
            }
            return(null);
        }
        public bool update(int id, SubCategory sc)
        {
            var           db       = new DatabaseContext();
            SubCategories existing = db.SubCategories.FirstOrDefault(u => u.Id == sc.ID);

            try
            {
                existing.Name         = sc.name;
                existing.CategoriesId = sc.catId;

                db.SaveChanges(id);
            }
            catch (Exception e)
            {
                writeToFile(e);
                return(false);
            }
            return(true);
        }
        public SubCategory SubCatDetails(int id)
        {
            try
            {
                var           db          = new DatabaseContext();
                SubCategories subcat      = (SubCategories)db.SubCategories.FirstOrDefault(c => c.Id == id);
                SubCategory   subcategory = new SubCategory()
                {
                    ID    = subcat.Id,
                    name  = subcat.Name,
                    catId = subcat.CategoriesId
                };

                return(subcategory);
            }
            catch (Exception e)
            {
                writeToFile(e);
                return(null);
            }
        }