public ValidationResult_OSC DeleteCategory(int categoryId)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var category = (from prodCat in entity.ProductCategories
                                    where prodCat.Id == categoryId
                                    select prodCat).First();

                    entity.ProductCategories.Remove(category);
                    entity.SaveChanges();

                    result.Success = true;
                    result.Message = "Product deleted successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
        public Result<List<OnlineShoppingCart.Model.ProductCategory>> GetAllCategoryList()
        {
            var result = new Result<List<OnlineShoppingCart.Model.ProductCategory>>();
            result.Data = new List<Model.ProductCategory>();
            using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
            {
                var listProdCat = new List<DataAccess.SQL.ProductCategory>();
                listProdCat = entity.ProductCategories.ToList();

                if (listProdCat == null || listProdCat.Count == 0)
                {
                    result.Success = false;
                    result.Data = null;
                    result.Message = "No product category found";
                }
                else
                {
                    foreach (var prodCat in listProdCat)
                    {
                        OnlineShoppingCart.Model.ProductCategory _productCategory = null;
                        prodCat.ConvertToBusinessObject(out _productCategory);
                        result.Data.Add(_productCategory);
                    }
                    result.Success = true;
                }
            }
            return result;
        }
        public ValidationResult_OSC AddListProductImageFilePath(List<OnlineShoppingCart.Model.ProductImageInfo> lstProductImageInfo)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    foreach (var productImageInfo in lstProductImageInfo)
                    {
                        OnlineShoppingCart.DataAccess.SQL.ProductImageFilePath _product = new DataAccess.SQL.ProductImageFilePath
                        {
                            ProductId = productImageInfo.ProductId,
                            ImageFilePath = productImageInfo.ImageFilePath,
                            IsIndexImage = productImageInfo.IsIndexImage
                        };
                        entity.ProductImageFilePaths.Add(_product);
                    }
                    entity.SaveChanges();

                    result.Success = true;
                    result.Message = "Product image path information inserted successfully";
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
        public ValidationResult_OSC AddCategory(OnlineShoppingCart.Model.ProductCategory category)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    OnlineShoppingCart.DataAccess.SQL.ProductCategory _category = new DataAccess.SQL.ProductCategory
                    {
                        Category = category.Category,
                        IsActive = category.IsActive,
                        CreatedOn = category.CreatedOn,
                        UpdatedOn = category.UpdatedOn,
                        CreatedByUserId = category.CreatedByUserID,
                        UpdatedByUserId = category.UpdatedByUserID
                    };

                    entity.ProductCategories.Add(_category);
                    entity.SaveChanges();

                    result.Success = true;
                    result.returnValue = Convert.ToString(_category.Id);
                    result.Message = "Product category inserted successfully";
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
        public Result<List<OnlineShoppingCart.Model.ProductImageInfo>> GetListProductImageFilePath(int productId)
        {
            using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
            {
                var result = new Result<List<OnlineShoppingCart.Model.ProductImageInfo>>();
                List<OnlineShoppingCart.DataAccess.SQL.ProductImageFilePath> lstProductImageFilePath = (from prod in entity.ProductImageFilePaths
                                                                                                        where prod.ProductId == productId
                                                                                                        select prod).ToList();

                if (lstProductImageFilePath == null || lstProductImageFilePath.Count == 0)
                {
                    result.Success = false;
                    result.Data = null;
                    result.Message = "No product image path information found";
                }
                else
                {
                    result.Data = new List<Model.ProductImageInfo>();
                    foreach (var productImageFilePath in lstProductImageFilePath)
                    {
                        OnlineShoppingCart.Model.ProductImageInfo productImageInfo = null;
                        productImageFilePath.ConvertToBusinessObject(out productImageInfo);
                        result.Data.Add(productImageInfo);
                    }
                }
                return result;
            }
        }
        public ValidationResult_OSC DeletProduct(int productId)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var product = (from t in entity.Products
                                   where t.Id == productId
                                   select t).First();

                    entity.Products.Remove(product);
                    entity.SaveChanges();

                    result.Success = true;
                    result.Message = "Product deleted successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
        public Result<List<OnlineShoppingCart.Model.Product>> GetProductList_GenericSearch(string productInfo, int categoryID)
        {
            var result = new Result<List<OnlineShoppingCart.Model.Product>>();
            result.Data = new List<Model.Product>();
            using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
            {
                var listProd = (from prod in entity.Products.Include("ProductCategories")
                                where (((productInfo == null || productInfo.Trim() == "")
                                  || prod.ProductCode.Contains(productInfo)
                                  || prod.ProductName.Contains(productInfo)
                                  || prod.ProductDescription.Contains(productInfo)
                                  || prod.Brand.Contains(productInfo)
                                  || prod.Model.Contains(productInfo))) && (categoryID == prod.CategoryId)
                                select new OnlineShoppingCart.Model.Product
                                {
                                    ID = prod.Id,
                                    ProductCode = prod.ProductCode,
                                    ProductName = prod.ProductName,
                                    ProductDescription = prod.ProductDescription,
                                    CategoryID = prod.CategoryId,
                                    CategoryName = prod.ProductCategory.Category,
                                    Brand = prod.Brand,
                                    Model = prod.Model,
                                    UnitPrice = prod.UnitPrice,
                                    SKU = prod.SKU,
                                    CurrentStock = prod.CurrentStock,
                                    IsActive = prod.IsActive,
                                    CreatedOn = prod.CreatedOn,
                                    UpdatedOn = prod.UpdatedOn,
                                    CreatedByUserID = prod.CreatedByUserId,
                                    UpdatedByUserID = prod.UpdatedByUserId
                                }).ToList();

                if (listProd == null)
                {
                    result.Success = false;
                    result.Data = null;
                    result.Message = "No product found for given search criteria";
                }
                else
                {
                    foreach (var _product in listProd)
                    {
                        DAL.ProductImage productImage = new ProductImage();
                        var resultProductImageList = productImage.GetListProductImageFilePath(_product.ID);

                        if (resultProductImageList.Success)
                            _product.ProductImageInfoList = resultProductImageList.Data;

                        result.Data.Add(_product);
                    }
                    result.Success = true;
                }
            }
            return result;
        }
        public ValidationResult_OSC AddProduct(OnlineShoppingCart.Model.Product product)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    OnlineShoppingCart.DataAccess.SQL.Product _product = new DataAccess.SQL.Product
                    {
                        Model = product.Model,
                        ProductCode = product.ProductCode,
                        ProductName = product.ProductName,
                        ProductDescription = product.ProductDescription,
                        CategoryId = product.CategoryID,
                        Brand = product.Brand,
                        UnitPrice = product.UnitPrice,
                        SKU = product.SKU,
                        CurrentStock = product.CurrentStock,
                        IsActive = product.IsActive,
                        CreatedOn = product.CreatedOn,
                        UpdatedOn = product.UpdatedOn,
                        CreatedByUserId = product.CreatedByUserID,
                        UpdatedByUserId = product.UpdatedByUserID
                    };
                    entity.Products.Add(_product);
                    entity.SaveChanges();

                    result.Success = true;
                    result.returnValue = Convert.ToString(_product.Id);
                    result.Message = "Product inserted successfully";
                }
                return result;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
        public ValidationResult_OSC UpdateCategory(OnlineShoppingCart.Model.ProductCategory category)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var _category = (from prodCat in entity.ProductCategories
                                     where prodCat.Id == category.ID
                                     select prodCat).First();

                    _category.Category = category.Category;
                    _category.IsActive = category.IsActive;
                    _category.CreatedOn = category.CreatedOn;
                    _category.UpdatedOn = category.UpdatedOn;
                    _category.CreatedByUserId = category.CreatedByUserID;
                    _category.UpdatedByUserId = category.UpdatedByUserID;

                    entity.SaveChanges();
                    result.Success = true;
                    result.Message = "Product category updated successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
 public Result<OnlineShoppingCart.Model.ProductCategory> GetCategory(int id)
 {
     using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
     {
         var result = new Result<OnlineShoppingCart.Model.ProductCategory>();
         OnlineShoppingCart.DataAccess.SQL.ProductCategory _productCategory = (from prod in entity.ProductCategories
                                                                               where prod.Id == id
                                                                               select prod).FirstOrDefault();
         if (_productCategory == null)
         {
             result.Success = false;
             result.Data = null;
             result.Message = "No product category found.";
         }
         else
         {
             OnlineShoppingCart.Model.ProductCategory _productCatModel = null;
             _productCategory.ConvertToBusinessObject(out _productCatModel);
             result.Data = _productCatModel;
         }
         return result;
     }
 }
        public Result<List<OnlineShoppingCart.Model.Product>> GetAllProduct()
        {
            var result = new Result<List<OnlineShoppingCart.Model.Product>>();
            result.Data = new List<Model.Product>();
            using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
            {
                var listProd = entity.Products.ToList();

                if (listProd == null)
                {
                    result.Success = false;
                    result.Data = null;
                    result.Message = "No product found";
                }
                else
                {
                    foreach (var it in listProd)
                    {
                        OnlineShoppingCart.Model.Product _product = null;
                        it.ConvertToBusinessObject(out _product);

                        DAL.ProductImage productImage = new ProductImage();
                        var resultProductImageList = productImage.GetListProductImageFilePath(_product.ID);

                        if (resultProductImageList.Success)
                            _product.ProductImageInfoList = resultProductImageList.Data;

                        result.Data.Add(_product);
                    }
                    result.Success = true;
                }
            }
            return result;
        }
        public ValidationResult_OSC UpdateProduct(OnlineShoppingCart.Model.Product product)
        {
            var result = new ValidationResult_OSC();
            try
            {
                using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
                {
                    var _p = (from t in entity.Products
                              where t.Id == product.ID
                              select t).First();

                    _p.Model = product.Model;
                    _p.ProductCode = product.ProductCode;
                    _p.ProductName = product.ProductName;
                    _p.ProductDescription = product.ProductDescription;
                    _p.CategoryId = product.CategoryID;
                    _p.Brand = product.Brand;
                    _p.UnitPrice = product.UnitPrice;
                    _p.SKU = product.SKU;
                    _p.CurrentStock = product.CurrentStock;
                    _p.IsActive = product.IsActive;
                    _p.CreatedOn = product.CreatedOn;
                    _p.UpdatedOn = product.UpdatedOn;
                    _p.CreatedByUserId = product.CreatedByUserID;
                    _p.UpdatedByUserId = product.UpdatedByUserID;

                    entity.SaveChanges();
                    result.Success = true;
                    result.Message = "Product updated successfully";
                    return result;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return result;
            }
        }
        public Result<OnlineShoppingCart.Model.Product> GetProduct(int id)
        {
            using (OnlineShoppingCartEntities entity = new OnlineShoppingCartEntities())
            {
                var result = new Result<OnlineShoppingCart.Model.Product>();
                OnlineShoppingCart.DataAccess.SQL.Product _product = (from prod in entity.Products
                                                                      where prod.Id == id
                                                                      select prod).FirstOrDefault();
                if (_product == null)
                {
                    result.Success = false;
                    result.Data = null;
                    result.Message = "No product found";
                }
                else
                {
                    OnlineShoppingCart.Model.Product _productModel = null;
                    _product.ConvertToBusinessObject(out _productModel);

                    DAL.ProductImage productImage = new ProductImage();
                    var resultProductImageList = productImage.GetListProductImageFilePath(_productModel.ID);

                    if (resultProductImageList.Success)
                        _productModel.ProductImageInfoList = resultProductImageList.Data;

                    result.Data = _productModel;
                }
                return result;
            }
        }