コード例 #1
0
 public ProductView GetProduct(int id)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         return(AutoMapper.Mapper.Map <Product, ProductView>(onlineShopContext.Product.Where(x => x.Id == id).FirstOrDefault()));
     }
 }
コード例 #2
0
 public IEnumerable <OrderView> GetUserOrders(string userId)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         return(AutoMapper.Mapper.Map <IEnumerable <Order>, IEnumerable <OrderView> >(onlineShopContext.Order.Where(x => x.AspNetUserId == userId)));
     }
 }
コード例 #3
0
 public IEnumerable <CategoryView> GetCategories()
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         return(AutoMapper.Mapper.Map <IEnumerable <Category>, IEnumerable <CategoryView> >(onlineShopContext.Category));
     }
 }
コード例 #4
0
 public IEnumerable <ProductView> GetProducts()
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         return(AutoMapper.Mapper.Map <IEnumerable <Product>, IEnumerable <ProductView> >(onlineShopContext.Product));
     }
 }
コード例 #5
0
 public IEnumerable <ProductReviewView> GetProductReviews(int id)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         return(AutoMapper.Mapper.Map <IEnumerable <ProductReview>, IEnumerable <ProductReviewView> >(onlineShopContext.ProductReview.Where(x => x.ProductId == id)));
     }
 }
コード例 #6
0
 public ProductView GetProductById(int id)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         var Product = onlineShopContext.Product.Find(id);
         return(AutoMapper.Mapper.Map <Product, ProductView>(Product));
     }
 }
コード例 #7
0
 public CategoryView GetCategoryById(int id)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         var category = onlineShopContext.Category.Find(id);
         return(AutoMapper.Mapper.Map <Category, CategoryView>(category));
     }
 }
コード例 #8
0
 public IEnumerable <CartView> GetCartProduct(string userId)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         var carts = onlineShopContext.Cart.Include(x => x.Product.Category).Where(x => x.AspNetUserId == userId);
         return(AutoMapper.Mapper.Map <IEnumerable <Cart>, IEnumerable <CartView> >(carts));
     }
 }
コード例 #9
0
 public async Task RemoveAllCart(string userId)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         var carts = onlineShopContext.Cart.Where(x => x.AspNetUserId == userId);
         onlineShopContext.Cart.RemoveRange(carts);
         await onlineShopContext.SaveChangesAsync();
     }
 }
コード例 #10
0
        private void AddProduct(ProductView Product)
        {
            var ProductAdd = AutoMapper.Mapper.Map <ProductView, Product>(Product);

            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                onlineShopContext.Product.Add(ProductAdd);
                onlineShopContext.SaveChanges();
            }
        }
コード例 #11
0
        private void AddCategory(CategoryView category)
        {
            var categoryAdd = AutoMapper.Mapper.Map <CategoryView, Category>(category);

            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                onlineShopContext.Category.Add(categoryAdd);
                onlineShopContext.SaveChanges();
            }
        }
コード例 #12
0
        public void AddProductReview(ProductReviewView productReviewView)
        {
            var productReview = AutoMapper.Mapper.Map <ProductReviewView, ProductReview>(productReviewView);

            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                productReview.ReviewDate = DateTime.Now;
                onlineShopContext.ProductReview.Add(productReview);
                onlineShopContext.SaveChanges();
            }
        }
コード例 #13
0
 public void RemoveProduct(int id)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         var Product = onlineShopContext.Product.Find(id);
         if (Product != null)
         {
             onlineShopContext.Product.Remove(Product);
             onlineShopContext.SaveChanges();
         }
     }
 }
コード例 #14
0
 public async Task RemoveFromCart(int id)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         Cart cart = onlineShopContext.Cart.Where(x => x.ProductId == id).FirstOrDefault();
         if (cart != null)
         {
             onlineShopContext.Cart.Remove(cart);
             await onlineShopContext.SaveChangesAsync();
         }
     }
 }
コード例 #15
0
 public void RemoveCategory(int id)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         var category = onlineShopContext.Category.Find(id);
         if (category != null)
         {
             onlineShopContext.Category.Remove(category);
             onlineShopContext.SaveChanges();
         }
     }
 }
コード例 #16
0
 public void CheckoutOrder(OrderView order)
 {
     using (var onlineShopContext = new OnlineShopWebEntities())
     {
         var newOrder = AutoMapper.Mapper.Map <OrderView, Order>(order);
         var product  = onlineShopContext.Product.Where(x => x.Id == order.TargetId).FirstOrDefault();
         newOrder.OrderDetails.Add(new OrderDetail {
             Product = product, Quantity = 1, UnitPrice = product.Price
         });
         onlineShopContext.Order.Add(newOrder);
         onlineShopContext.SaveChanges();
     }
 }
コード例 #17
0
        public CatalogResult GetCatalog(int pageSize, string search = null, int page = 0, int?category = null)
        {
            CatalogResult catalogPager = new CatalogResult();

            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                var products = onlineShopContext.Product.Where(x => (category == null || x.CategoryId == category) && (search == null || x.Name.Contains(search))).OrderBy(x => x.Id);
                catalogPager.MoreResults = products.Count() - (pageSize * (page + 1));
                var pageProducts = products.Skip(pageSize * page).Take(pageSize);
                catalogPager.Products = AutoMapper.Mapper.Map <IEnumerable <Product>, IEnumerable <ProductView> >(pageProducts);
            }
            return(catalogPager);
        }
コード例 #18
0
        private void UpdateProduct(ProductView Product)
        {
            var ProductUpdate = AutoMapper.Mapper.Map <ProductView, Product>(Product);

            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                var ProductOriginal = onlineShopContext.Product.Find(Product.Id);
                if (Product != null)
                {
                    onlineShopContext.Entry(ProductOriginal).CurrentValues.SetValues(ProductUpdate);
                    onlineShopContext.SaveChanges();
                }
            }
        }
コード例 #19
0
        private void UpdateCategory(CategoryView category)
        {
            var categoryUpdate = AutoMapper.Mapper.Map <CategoryView, Category>(category);

            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                var categoryOriginal = onlineShopContext.Category.Find(category.Id);
                if (category != null)
                {
                    onlineShopContext.Entry(categoryOriginal).CurrentValues.SetValues(categoryUpdate);
                    onlineShopContext.SaveChanges();
                }
            }
        }
コード例 #20
0
        public OrderView GetOrderReview(int targetId)
        {
            OrderView order = new OrderView {
                TargetId = targetId, OrderType = Enums.OrderTypeEnum.SingleProduct, OrderTypeInt = (int)Enums.OrderTypeEnum.SingleProduct, OrderStatusId = 1
            };

            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                var product = AutoMapper.Mapper.Map <Product, ProductView>(onlineShopContext.Product.Where(x => x.Id == targetId).FirstOrDefault());
                order.OrderDetails.Add(new OrderDetailView {
                    Product = product, Quantity = 1
                });
            }
            return(order);
        }
コード例 #21
0
ファイル: AllCart.cs プロジェクト: sss-software/OnlineShop
        public void CheckoutOrder(OrderView order)
        {
            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                var newOrder = AutoMapper.Mapper.Map <OrderView, Order>(order);
                var carts    = onlineShopContext.Cart.Where(x => x.AspNetUserId == order.AspNetUserId);

                foreach (var cart in carts)
                {
                    newOrder.OrderDetails.Add(new OrderDetail {
                        Product = cart.Product, Quantity = cart.Quantity, UnitPrice = cart.Product.Price
                    });
                }

                onlineShopContext.Order.Add(newOrder);
                onlineShopContext.Cart.RemoveRange(carts);
                onlineShopContext.SaveChanges();
            }
        }
コード例 #22
0
ファイル: AllCart.cs プロジェクト: sss-software/OnlineShop
        public OrderView GetOrderReview(int targetId)
        {
            OrderView order = new OrderView {
                TargetId = targetId, OrderType = Enums.OrderTypeEnum.AllCart, OrderTypeInt = (int)Enums.OrderTypeEnum.AllCart, OrderStatusId = 1
            };

            if (HttpContext.Current != null)
            {
                var userId = HttpContext.Current.User.Identity.GetUserId();
                using (var onlineShopContext = new OnlineShopWebEntities())
                {
                    var carts = onlineShopContext.Cart.Where(x => x.AspNetUserId == userId).ToList();
                    order.OrderDetails = carts.Select(x => new OrderDetailView {
                        Product = AutoMapper.Mapper.Map <Product, ProductView>(x.Product), Quantity = x.Quantity
                    }).ToList();
                }
            }
            return(order);
        }
コード例 #23
0
        public void AddToCart(int id, string userId)
        {
            using (var onlineShopContext = new OnlineShopWebEntities())
            {
                Cart cart = onlineShopContext.Cart.Where(x => x.AspNetUserId == userId && x.ProductId == id).FirstOrDefault();
                if (cart == null)
                {
                    cart = new Cart {
                        AspNetUserId = userId, ProductId = id, Quantity = 1, DateCreated = DateTime.Now
                    };
                    onlineShopContext.Cart.Add(cart);
                }
                else
                {
                    cart.Quantity++;
                }

                onlineShopContext.SaveChanges();
            }
        }