//********************Save category

        public void SaveCategory(Category category)
        {
            using (var context = new FAContext())
            {
                context.Categories.Add(category);
                context.SaveChanges();
            }
        }
        //********************Update category


        public void UpdateCategory(Category category)
        {
            using (var context = new FAContext())
            {
                context.Entry(category).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
Beispiel #3
0
        //********************Update Products

        public void UpdateProduct(Product Product)
        {
            using (var context = new FAContext())
            {
                context.Entry(Product).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
Beispiel #4
0
 public int SaveOrder(Order order)
 {
     using (var context = new FAContext())
     {
         context.Orders.Add(order);
         return(context.SaveChanges());
     }
 }
Beispiel #5
0
 public object UpdateOrderStatus(int ID, string status)
 {
     using (var context = new FAContext())
     {
         var order = context.Orders.Find(ID);
         order.status = status;
         context.Entry(order).State = EntityState.Modified;
         return(context.SaveChanges() > 0);
     }
 }
Beispiel #6
0
        //********************Save Products

        public void SaveProduct(Product Product)
        {
            using (var context = new FAContext())
            {
                context.Entry(Product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(Product);
                context.SaveChanges();
            }
        }
Beispiel #7
0
        //********************Delete Products

        public void DeleteProduct(int ID)
        {
            using (var context = new FAContext())
            {
                var Product = context.Products.Find(ID);

                context.Products.Remove(Product);

                context.SaveChanges();
            }
        }
        //********************Delete category*****

        public void DeleteCategory(int ID)
        {
            using (var context = new FAContext())
            {
                var categoty = context.Categories.Where(x => x.ID == ID).Include(x => x.Products).FirstOrDefault();

                context.Products.RemoveRange(categoty.Products);

                context.Categories.Remove(categoty);

                context.SaveChanges();
            }
        }