コード例 #1
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
 //create order with creating list of orderItems { orderId , productId }
 public int SaveOrder(Order order)
 {
     using (var context = new eComContext())
     {
         context.Orders.Add(order);
         return(context.SaveChanges());
     }
 }
コード例 #2
0
ファイル: ConfigurationService.cs プロジェクト: muswilam/eCom
 //edit config value
 public bool EditConfig(Config config)
 {
     using (var context = new eComContext())
     {
         context.Entry(config).State = EntityState.Modified;
         return(context.SaveChanges() > 0);
     }
 }
コード例 #3
0
 //create category
 public void SaveCategory(Category category)
 {
     using (var context = new eComContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
コード例 #4
0
 //edit category
 public void UpdateCategory(Category category)
 {
     using (var context = new eComContext())
     {
         context.Entry(category).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #5
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
 //edit product
 public void UpdateProduct(Product product)
 {
     using (var context = new eComContext())
     {
         context.Entry(product).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #6
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
 //create wishlist
 public bool SaveWishlist(Wishlist wishlist)
 {
     using (eComContext context = new eComContext())
     {
         context.Wishlists.Add(wishlist);
         return(context.SaveChanges() > 0);
     }
 }
コード例 #7
0
ファイル: ReviewService.cs プロジェクト: muswilam/eCom
        //create a new review
        public bool SaveReview(Review newReview)
        {
            using (var context = new eComContext())
            {
                context.Reviews.Add(newReview);

                return(context.SaveChanges() > 0);
            }
        }
コード例 #8
0
ファイル: ReviewService.cs プロジェクト: muswilam/eCom
        //delete review
        public void RemoveReview(int id)
        {
            using (var context = new eComContext())
            {
                var review = context.Reviews.Where(r => r.Id == id).First();

                context.Reviews.Remove(review);
                context.SaveChanges();
            }
        }
コード例 #9
0
        //delete category
        public void DeleteCategory(int id)
        {
            using (var context = new eComContext())
            {
                var category = context.Categories.Find(id);

                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
コード例 #10
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
        //delete product
        public void DeleteProduct(int id)
        {
            using (var context = new eComContext())
            {
                var product = context.Products.Find(id);

                context.Products.Remove(product);
                context.SaveChanges();
            }
        }
コード例 #11
0
ファイル: ProductService.cs プロジェクト: muswilam/eCom
        //add product
        public void SaveProduct(Product product)
        {
            using (var context = new eComContext())
            {
                context.Entry(product.Category).State = EntityState.Unchanged; //prevent adding category again with different id

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
コード例 #12
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
        //Empty wishlistItems by userId
        public bool EmptyWishlistItems(string userId)
        {
            using (eComContext context = new eComContext())
            {
                var wishlist = context.Wishlists.Where(w => w.UserId == userId).Include(w => w.WishlistItems).FirstOrDefault();

                context.WishlistItems.RemoveRange(wishlist.WishlistItems);
                return(context.SaveChanges() > 0);
            }
        }
コード例 #13
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
 //edit wishlist
 public bool AddWishlistItem(List <WishlistItem> WishlistItems)
 {
     using (eComContext context = new eComContext())
     {
         foreach (var wishItem in WishlistItems)
         {
             context.WishlistItems.Add(wishItem);
         }
         return(context.SaveChanges() > 0);
     }
 }
コード例 #14
0
ファイル: OrderService.cs プロジェクト: muswilam/eCom
        //edit order status (by admin)
        public bool UpdateOrderStatus(string status, int id)
        {
            using (var context = new eComContext())
            {
                var order = context.Orders.Where(o => o.Id == id).FirstOrDefault();

                order.Status = status;

                context.Entry(order).State = EntityState.Modified;
                return(context.SaveChanges() > 0);
            }
        }
コード例 #15
0
ファイル: ConfigurationService.cs プロジェクト: muswilam/eCom
 //update main picture in home page (by admin)
 public bool UpdateMainPicture(string key, string imageUrl)
 {
     using (var context = new eComContext())
     {
         var existConfig = context.Configurations.Where(c => c.Key == key).FirstOrDefault();
         if (existConfig != null)
         {
             existConfig.Value = imageUrl;
             context.Entry(existConfig).State = EntityState.Modified;
             return(context.SaveChanges() > 0);
         }
         return(false);
     }
 }
コード例 #16
0
ファイル: WishlistService.cs プロジェクト: muswilam/eCom
        //remove product from wishlist
        public bool RemoveItemFromWishlist(string userId, int productId)
        {
            using (eComContext context = new eComContext())
            {
                var wishlistItems = context.WishlistItems.Where(wi => wi.Wishlist.UserId == userId).ToList();

                foreach (var wishItem in wishlistItems)
                {
                    if (wishItem.ProductId == productId)
                    {
                        context.WishlistItems.Remove(wishItem);
                        return(context.SaveChanges() > 0);
                    }
                }
                return(false);
            }
        }