//function to get the details of the product using name of the product
        public ProductDetailDTO GetDetail(ProductDetailDTO productDetailDTO)
        {
            Product  product  = dbContext.Product.Where(a => a.Name == productDetailDTO.Name).FirstOrDefault();
            Category category = dbContext.Category.Where(ab => ab.ID == product.CategoryID).FirstOrDefault();

            dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
            if (product != null)
            {
                ProductDetailDTO newBasicDTO = new ProductDetailDTO();
                newBasicDTO.Name        = product.Name;
                newBasicDTO.ID          = product.ID;
                newBasicDTO.Description = product.Description;
                newBasicDTO.CatName     = category.Name;
                newBasicDTO.Variants    = (from v in dbContext.Variant.Where(cdf => cdf.ProductID == product.ID)
                                           join vp in dbContext.VariantProperty on v.ID equals vp.VariantID
                                           join img in dbContext.VariantImage on v.ID equals img.VariantID
                                           join vpv in dbContext.VariantPropertyValue on vp.PropertyValueID equals vpv.ID
                                           join p in dbContext.Property on vpv.PropertyID equals p.ID
                                           join value in dbContext.Value on vpv.ValueID equals value.ID
                                           select new VariantDTO()
                {
                    VariantId = v.ID,
                    ListingPrice = v.ListingPrice,
                    Discount = v.Discount,
                    Variant_Property = p.Name,
                    Variant_Value1 = value.Name,
                    image = img.ImageURL
                });
                Variant      var = dbContext.Variant.Where(cdf => cdf.ProductID == product.ID).FirstOrDefault();
                VariantImage ima = dbContext.VariantImage.Where(cd => cd.VariantID == var.ID).First();
                newBasicDTO.ImageURL     = ima.ImageURL;
                newBasicDTO.ListingPrice = var.ListingPrice;
                newBasicDTO.Discount     = var.Discount;
                return(newBasicDTO);
            }
            return(null);
        }
        //adding product to the cart using the loggedin user's userID
        public bool AddProduct(Guid id, Guid user_id)
        {
            Product product = dbContext.Product.Where(a => a.ID == id).FirstOrDefault();

            if (product == null)
            {
                dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
                Variant variant = dbContext.Variant.Where(s => s.ID == id).FirstOrDefault();

                Guid               p_id    = variant.ProductID;
                Product            pr      = dbContext.Product.Where(cdd => cdd.ID == p_id).FirstOrDefault();
                VariantImage       vimage  = dbContext.VariantImage.Where(cdd => cdd.VariantID == variant.ID).FirstOrDefault();
                ProductDetailDTO   cartdto = new ProductDetailDTO();
                IEnumerable <Cart> ca      = dbContext.Cart.Where(pd => pd.UserID == user_id);
                foreach (var cd in ca)
                {
                    if (cd.VariantID == variant.ID)
                    {
                        return(false);
                    }
                }

                Cart cart = new Cart();
                cart.ID           = Guid.NewGuid();
                cart.VariantID    = variant.ID;
                cart.SellingPrice = variant.Discount;
                cart.Qty          = 1;
                cart.UserID       = user_id;
                cartdto.Name      = pr.Name;
                cartdto.ImageURL  = vimage.ImageURL;
                dbContext.Cart.Add(cart);
                dbContext.SaveChanges();
                return(true);
            }
            else
            {
                dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
                Variant variant = dbContext.Variant.Where(s => s.ProductID == id).FirstOrDefault();
                //Guid p_id = variant.ProductID;
                VariantImage       vimage  = dbContext.VariantImage.Where(cdd => cdd.VariantID == variant.ID).FirstOrDefault();
                ProductDetailDTO   cartdto = new ProductDetailDTO();
                IEnumerable <Cart> ca      = dbContext.Cart.Where(pd => pd.UserID == user_id);
                foreach (var cd in ca)
                {
                    if (cd.VariantID == variant.ID)
                    {
                        return(false);
                    }
                }
                Cart cart = new Cart();
                cart.ID           = Guid.NewGuid();
                cart.VariantID    = variant.ID;
                cart.SellingPrice = variant.Discount;
                cart.Qty          = 2;
                cart.UserID       = user_id;
                cartdto.Name      = product.Name;
                cartdto.ImageURL  = vimage.ImageURL;
                dbContext.Cart.Add(cart);
                dbContext.SaveChanges();
                return(true);
            }
        }