Exemple #1
0
        public int SelectCart(int userId)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                if (db.Cart.Any(x => x.UserId == userId && x.Checkout == false && x.Delivered == false))
                {
                    db.SaveChanges();
                }
                else
                {
                    var createCart = new Cart
                    {
                        UserId     = userId,
                        Checkout   = false,
                        Delivered  = false,
                        TotalPrice = 0
                    };

                    db.Cart.Add(createCart);
                    db.SaveChanges();
                }
                var selectCart = db.Cart.Where(x => x.UserId == userId && x.Checkout == false && x.Delivered == false)
                                 .Select(x => x.CartId).SingleOrDefault();

                return(selectCart);
            }
        }
Exemple #2
0
 public void AddProductToCartUser(int productId, int productQuantity, int cartId)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         if (db.ProductInCart.Any(x => x.CartId == cartId && x.BagId == productId))
         {
             var productInCart = db.ProductInCart
                                 .Where(x => x.CartId == cartId && x.BagId == productId)
                                 .ToList();
             foreach (var item in productInCart)
             {
                 item.Quantity += productQuantity;
             }
             db.SaveChanges();
         }
         else
         {
             var productInCart = new ProductInCart
             {
                 BagId        = productId,
                 Price        = db.Product.Where(x => x.BagId == productId).Select(x => x.Price).SingleOrDefault(),
                 Quantity     = productQuantity,
                 DateDelivery = DateTime.Now.AddDays(3),
                 CartId       = cartId
             };
             db.ProductInCart.Add(productInCart);
             db.SaveChanges();
         }
     }
 }
Exemple #3
0
 public User GetUser(string username)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         return(db.User.SingleOrDefault(x => x.Username == username));
     }
 }
Exemple #4
0
 public User CheckLogin(string username, string password)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var userData = db.User.SingleOrDefault(x => x.Username == username && x.Password == password);
         return(userData);
     }
 }
Exemple #5
0
        public bool CheckOutCart(int userId)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var cartStatus = db.Cart.Any(x => x.UserId == userId && x.Checkout == false);

                return(cartStatus);
            }
        }
Exemple #6
0
        public void DeleteInCart(int productInCartId)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var delete = db.ProductInCart.Find(productInCartId);

                db.ProductInCart.Remove(delete);
                db.SaveChanges();
            }
        }
Exemple #7
0
        public void CheckoutProduct(int orderId)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var statusDelivery = db.Cart
                                     .FirstOrDefault(x => x.CartId == orderId);

                statusDelivery.Checkout = true;
                db.SaveChanges();
            }
        }
Exemple #8
0
 public void DeleteProductInStock(List <CartModel> productCart)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         foreach (var item in productCart)
         {
             var stock = db.Product.Where(x => x.BagName == item.ProductName).Select(x => x.Stock).FirstOrDefault();
             stock -= item.Quantity;
             db.SaveChanges();
         }
     }
 }
Exemple #9
0
 public List <BrandType> GetProductBrand()
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var productBrand = db.BrandProduct.Select(x => new BrandType
         {
             BrandId   = x.BrandId,
             BrandName = x.BrandName
         }).ToList();
         return(productBrand);
     }
 }
Exemple #10
0
        public List <ProductType> GetProductType()
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var eachProduct = db.TypeProduct.Select(x => new ProductType
                {
                    ProductTypeId   = x.TypeId,
                    ProductTypeName = x.TypeName
                }).ToList();

                return(eachProduct);
            }
        }
Exemple #11
0
 public void AddNewPhotoProduct(string filename, int productId)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var picture = new Picture()
         {
             PictureName = filename,
             BagId       = productId
         };
         db.Picture.Add(picture);
         db.SaveChanges();
     }
 }
Exemple #12
0
        public List <PhotoList> GetAllOfSelectedPicture(int bagIdFromSelectedProduct)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var allImageOfSelectedPicture = db.Picture
                                                .Where(x => x.BagId == bagIdFromSelectedProduct)
                                                .Select(x => new PhotoList
                {
                    PictureName = x.PictureName,
                }).ToList();

                return(allImageOfSelectedPicture);
            }
        }
Exemple #13
0
 public void SentProduct(int orderId)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var statusSent = db.Cart
                          .Where(x => x.CartId == orderId)
                          .ToList();
         foreach (var item in statusSent)
         {
             item.Delivered = true;
         }
         db.SaveChanges();
     }
 }
Exemple #14
0
        public List <PhotoList> GetAllPicture()
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var photoListAll = db.Picture.Select(x => new PhotoList
                {
                    PictureId      = x.PictureId,
                    PictureName    = x.PictureName,
                    ProductBagName = x.Product.BagName,
                    ProductBagId   = x.BagId
                }).DistinctBy(x => x.ProductBagId).ToList();

                return(photoListAll);
            }
        }
Exemple #15
0
 public void UploadSlipPicture(string fileName, int cartId, decimal totalPrice)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var uploadSlip = db.Cart
                          .Where(x => x.CartId == cartId)
                          .ToList();
         foreach (var item in uploadSlip)
         {
             item.TotalPrice = totalPrice;
             item.Slip       = fileName;
         }
         db.SaveChanges();
     }
 }
Exemple #16
0
        public void SaveUser(RegisterViewModel dataUser)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var UserData = db.User
                               .SingleOrDefault(x => x.UserId == dataUser.UserId); ////// - selest ID - /////

                UserData.Name        = dataUser.Name;
                UserData.LastName    = dataUser.LastName;
                UserData.CreditCard  = dataUser.CreditCard;
                UserData.Address     = dataUser.Address;
                UserData.Description = dataUser.Description;
                db.SaveChanges();
            }
        }
Exemple #17
0
 public void UploadPhotoProduct(string filename)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var picture = new Picture()
         {
             PictureName = filename,
             BagId       = db.Product
                           .Select(x => x.BagId)
                           .Max()
         };
         db.Picture.Add(picture);
         db.SaveChanges();
     }
 }
Exemple #18
0
        public List <PhotoList> GetPictureOfTypeSelected(int typeId)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var selectedTypePicture = db.Picture.Where(x => x.Product.TypeId == typeId)
                                          .Select(x => new PhotoList
                {
                    PictureId      = x.PictureId,
                    PictureName    = x.PictureName,
                    ProductBagId   = x.BagId,
                    ProductBagName = x.Product.BagName
                }).DistinctBy(x => x.ProductBagId).ToList();

                return(selectedTypePicture);
            }
        }
Exemple #19
0
        public List <PhotoList> GetPictureBySearch(string searchKey)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var searchForPicture = db.Picture.Where(x => x.Product.BagName.ToLower().Contains(searchKey.ToLower()) || x.Product.BrandProduct.BrandName.ToLower().Contains(searchKey.ToLower()) || x.Product.TypeProduct.TypeName.ToLower().Contains(searchKey.ToLower()))
                                       .Select(x => new PhotoList
                {
                    PictureId      = x.PictureId,
                    PictureName    = x.PictureName,
                    ProductBagId   = x.BagId,
                    ProductBagName = x.Product.BagName
                }).DistinctBy(x => x.ProductBagId).ToList();

                return(searchForPicture);
            }
        }
Exemple #20
0
        public ProductItemInfo GetInfoProduct(int bagId)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var itemInfo = db.Product.Where(x => x.BagId == bagId).Select(x => new ProductItemInfo
                {
                    ProductId   = x.BagId,
                    ProductName = x.BagName,
                    Description = x.Description,
                    Price       = x.Price,
                    Available   = x.Available,
                    Stock       = x.Stock
                }).SingleOrDefault();

                return(itemInfo);
            }
        }
Exemple #21
0
 public void AddNewProduct(HomeListItem editProductData)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var product = new Product()
         {
             BagName     = editProductData.ProductItemInfo.ProductName,
             BrandId     = editProductData.SelectedBrandType,
             TypeId      = editProductData.SelectedProductType,
             Price       = editProductData.ProductItemInfo.Price,
             Description = editProductData.ProductItemInfo.Description,
             Available   = editProductData.ProductItemInfo.Available,
             Stock       = editProductData.ProductItemInfo.Stock
         };
         db.Product.Add(product);
         db.SaveChanges();
     }
 }
Exemple #22
0
        public void EditProductInformation(HomeListItem editProductData)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var product = db.Product
                              .SingleOrDefault(x => x.BagId == editProductData.ProductItemInfo.ProductId);

                product.BagId       = editProductData.ProductItemInfo.ProductId;
                product.BagName     = editProductData.ProductItemInfo.ProductName;
                product.Price       = editProductData.ProductItemInfo.Price;
                product.Description = editProductData.ProductItemInfo.Description;
                product.Available   = editProductData.ProductItemInfo.Available;
                product.TypeId      = editProductData.SelectedProductType;
                product.BrandId     = editProductData.SelectedBrandType;
                product.Stock       = editProductData.ProductItemInfo.Stock;
                db.SaveChanges();
            }
        }
Exemple #23
0
 public List <HistoryPaymentModel> HistoryUserPayment(int userId)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var history = db.ProductInCart
                       .Where(x => x.Cart.UserId == userId && x.Cart.Slip != null)
                       .Select(x => new HistoryPaymentModel
         {
             CartId      = x.Cart.CartId,
             ProductName = x.Product.BagName,
             Price       = x.Price,
             ImageName   = x.Product.Picture.Select(img => img.PictureName).FirstOrDefault(),
             Quantity    = x.Quantity,
             ProductId   = x.Product.BagId,
             Status      = x.Cart.Delivered
         }).OrderByDescending(x => x.CartId).ToList();
         return(history);
     }
 }
Exemple #24
0
 public void Register(RegisterViewModel dataUer)
 {
     using (var db = new Bagaround_ShopEntities1())
     {
         var UserData = new Entity.User()
         {
             Username   = dataUer.Username,
             Password   = dataUer.Password,
             Name       = dataUer.Name,
             LastName   = dataUer.LastName,
             CreditCard = dataUer.CreditCard,
             Email      = dataUer.Email,
             Address    = dataUer.Address,
             Role       = "User"
         };
         db.User.Add(UserData);
         db.SaveChanges();
     }
 }
Exemple #25
0
        public List <CartModel> SelectProductInCart(int cartId)
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var listSelectProduct = db.ProductInCart
                                        .Where(x => x.CartId == cartId && x.Product.Available == true)
                                        .Select(x => new CartModel
                {
                    CartId          = cartId,
                    Slip            = x.Cart.Slip,
                    ProductInCartId = x.PaymentId,
                    ProductId       = x.BagId,
                    Quantity        = x.Quantity,
                    ProductName     = x.Product.BagName,
                    ProductPrice    = x.Product.Price,
                    ProductImage    = x.Product.Picture.Select(picName => picName.PictureName).FirstOrDefault()
                }).ToList();

                return(listSelectProduct);
            }
        }
Exemple #26
0
        public List <Order> SelectOrder()
        {
            using (var db = new Bagaround_ShopEntities1())
            {
                var listOrder = db.Cart
                                .Where(x => x.ProductInCart.Select(carId => carId.PaymentId).ToList().Count != 0 && x.Slip != null)
                                .Select(x => new Order
                {
                    OrderId      = x.CartId,
                    OwnerName    = x.User.Name,
                    CheckOut     = x.Checkout,
                    Delivery     = x.Delivered,
                    ProductName  = x.ProductInCart.Select(bag => bag.Product.BagName).ToList(),
                    OwnerAddress = x.User.Address,
                    Quantity     = x.ProductInCart.Select(quan => quan.Quantity).ToList(),
                    Slip         = x.Slip,
                    TotalPrice   = x.TotalPrice
                }
                                        ).OrderBy(x => x.CheckOut && x.Delivery).ToList();

                return(listOrder);
            }
        }