Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            }
        }