Exemplo n.º 1
0
        public IEnumerable <MasterProductResult> GetASMasterProductByID(long MasterCategoryId, long MasterSubCategoryId, long MasterBrandId)
        {
            try
            {
                //Get Parent Product data as per MasterCategoryId Or MasterSubCategoryId Or  MasterBranchId
                var _data = (from MP in _Context.ASMasterProducts
                             join MB in _Context.ASMasterBrands on MP.MasterBrandId equals MB.MasterBrandId into MBGroup
                             from MB in MBGroup.DefaultIfEmpty()
                             join SC in _Context.ASMasterSubCategories on MP.MasterSubCategoryId equals SC.MasterSubCategoryId into SCGroup
                             from SC in SCGroup.DefaultIfEmpty()
                             join CA in _Context.ASMasterCategories on SC.MasterCategoryId equals CA.MasterCategoryId into CAGroup
                             from CA in CAGroup.DefaultIfEmpty()
                             where (MasterCategoryId > 0 && MasterSubCategoryId == 0 && MasterBrandId == 0 && SC.MasterCategoryId == MasterCategoryId) ||
                             (MasterCategoryId == 0 && MasterSubCategoryId > 0 && MasterBrandId == 0 && MP.MasterSubCategoryId == MasterSubCategoryId) ||
                             (MasterCategoryId == 0 && MasterSubCategoryId == 0 && MasterBrandId > 0 && MP.MasterBrandId == MasterBrandId)
                             select new
                {
                    MP.MasterProductId,
                    MP.ProductTitle,
                    MP.ProductSKU,
                    MP.ProductHSNCode,
                    MP.ProductBarCode,
                    MP.ProductMainImage,
                    MP.Description,
                    MP.Specification,
                    MP.LegalDisclamer,
                    MP.SafetyWarning,
                    MP.ProductModel,
                    MP.Manufacturer,
                    MP.DepreciatePercentage,
                    MP.ReorderLevel,
                    MP.CountryOfOrigin,
                    //CO.CountryTitle,
                    MP.ProductTaxCode,
                    //MT.TaxTitle,
                    //MT.IsTaxPercentageAmount,
                    //MT.TaxValue,
                    MP.ProductCurrency,
                    //MC.CurrencyTitle,
                    MP.Sequence,
                    MP.IsActive,
                    MP.EnterById,
                    MP.EnterDate,
                    MP.ModifiedById,
                    MP.ModifiedDate,
                    MP.MasterBrandId,
                    MB.BrandTitle,
                    MP.MasterSubCategoryId,
                    SC.SubCategoryTitle,
                    CA.CategoryTitle,
                    CA.MasterCategoryId
                });

                var _AdminCountries  = _AdminContext.ADMasterCountries.ToList();
                var _AdminTaxes      = _AdminContext.ADMasterTaxes.ToList();
                var _AdminCurrencies = _AdminContext.ADMasterCurrencies.ToList();
                var _AdminBranches   = _AdminContext.ADMasterBranches.ToList();
                var _AdminEmployees  = _AdminContext.ADMasterEmployees.ToList();
                var _AdminVendors    = _AdminContext.ADMasterVendors.ToList();

                //Get Child Product data as per MasterCategoryId Or MasterSubCategoryId Or  MasterBranchId
                var _Productdata = (from MC in _Context.ASMasterCategories
                                    join MSC in _Context.ASMasterSubCategories on MC.MasterCategoryId equals MSC.MasterCategoryId
                                    join MP in _Context.ASMasterProducts on MSC.MasterSubCategoryId equals MP.MasterSubCategoryId into MPGroup
                                    from MP in MPGroup.DefaultIfEmpty()
                                    join MPC in _Context.ASMasterProductChilds on MP.MasterProductId equals MPC.MasterProductId into MPCGroup
                                    from MPC in MPCGroup.DefaultIfEmpty()
                                    where (MasterCategoryId > 0 && MasterSubCategoryId == 0 && MasterBrandId == 0 && MSC.MasterCategoryId == MasterCategoryId) ||
                                    (MasterCategoryId == 0 && MasterSubCategoryId > 0 && MasterBrandId == 0 && MP.MasterSubCategoryId == MasterSubCategoryId) ||
                                    (MasterCategoryId == 0 && MasterSubCategoryId == 0 && MasterBrandId > 0 && MP.MasterBrandId == MasterBrandId)
                                    select new
                {
                    MC.MasterCategoryId,
                    MC.CategoryTitle,
                    MSC.MasterSubCategoryId,
                    MSC.SubCategoryTitle,
                    MPC.MasterProductId,
                    MPC.ProductChildTitle,
                    MPC.ProductChildSKU,
                    MPC.ManufacturerPartNumber,
                    MPC.PurchasePrice,
                    MPC.DepreciatePrice,
                    MPC.IsActive,
                    MPC.IsDeadAssets,
                    MPC.IsSaleProduct,
                    MPC.MasterBranchId,
                    MPC.MasterEmployeeId,
                    MPC.WarrantyExpiryDate
                });

                //insert search data in model List<MasterProductResult> object with parent and child
                List <MasterProductResult> objMasterProductResultList = new List <MasterProductResult>();

                foreach (var _Item in _data.ToList())
                {
                    MasterProductResult _MasterProductResult = new MasterProductResult();
                    _MasterProductResult.MasterProductId      = _Item.MasterProductId;
                    _MasterProductResult.ProductTitle         = _Item.ProductTitle;
                    _MasterProductResult.MasterBrandId        = _Item.MasterBrandId;
                    _MasterProductResult.BrandTitle           = _Item.BrandTitle;
                    _MasterProductResult.MasterSubCategoryId  = _Item.MasterSubCategoryId;
                    _MasterProductResult.SubCategoryTitle     = _Item.SubCategoryTitle;
                    _MasterProductResult.MasterCategoryId     = _Item.MasterCategoryId;
                    _MasterProductResult.CategoryTitle        = _Item.CategoryTitle;
                    _MasterProductResult.ProductSKU           = _Item.ProductSKU;
                    _MasterProductResult.ProductHSNCode       = _Item.ProductHSNCode;
                    _MasterProductResult.ProductBarCode       = _Item.ProductBarCode;
                    _MasterProductResult.ProductMainImage     = _Item.ProductMainImage;
                    _MasterProductResult.Description          = _Item.Description;
                    _MasterProductResult.Specification        = _Item.Specification;
                    _MasterProductResult.LegalDisclamer       = _Item.LegalDisclamer;
                    _MasterProductResult.SafetyWarning        = _Item.SafetyWarning;
                    _MasterProductResult.ProductModel         = _Item.ProductModel;
                    _MasterProductResult.Manufacturer         = _Item.Manufacturer;
                    _MasterProductResult.DepreciatePercentage = _Item.DepreciatePercentage;
                    _MasterProductResult.ReorderLevel         = _Item.ReorderLevel;
                    _MasterProductResult.CountryOfOrigin      = _Item.CountryOfOrigin;
                    _MasterProductResult.CountryOfOriginTitle = _AdminCountries.Where(a => a.MasterCountryId == _Item.CountryOfOrigin).Select(a => a.CountryTitle).FirstOrDefault();
                    _MasterProductResult.ProductTaxCode       = _Item.ProductTaxCode;
                    _MasterProductResult.ProductTaxCodeTitle  = _AdminTaxes.Where(a => a.MasterTaxId == _Item.ProductTaxCode).Select(a => a.TaxTitle).FirstOrDefault();
                    _MasterProductResult.ProductCurrency      = _Item.ProductCurrency;
                    _MasterProductResult.ProductCurrencyTitle = _AdminCurrencies.Where(a => a.MasterCurrencyId == _Item.ProductCurrency).Select(a => a.CurrencyTitle).FirstOrDefault();;

                    _MasterProductResult.TotalAssetsInStock          = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == true && a.IsDeadAssets == false && a.IsSaleProduct == false).Count());
                    _MasterProductResult.AssetsAssign                = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == true && a.IsDeadAssets == false && a.IsSaleProduct == false && (a.MasterEmployeeId != 0)).Count());
                    _MasterProductResult.AssetsInRepair              = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == false && a.IsDeadAssets == false && a.IsSaleProduct == false).Count());
                    _MasterProductResult.ServiceInExpire             = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.WarrantyExpiryDate <= DateTime.Now && a.IsActive == true && a.IsDeadAssets == false && a.IsSaleProduct == false).Count());
                    _MasterProductResult.AssetsInSold                = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == false && a.IsDeadAssets == false && a.IsSaleProduct == true).Count());
                    _MasterProductResult.AssetsInDead                = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == false && a.IsDeadAssets == true && a.IsSaleProduct == false).Count());
                    _MasterProductResult.TotalAssetsCost             = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsDeadAssets == false && a.IsSaleProduct == false).Sum(a => a.PurchasePrice) ?? 0);
                    _MasterProductResult.TotalAssetsDepreciatedValue = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsDeadAssets == false && a.IsSaleProduct == false).Sum(a => a.DepreciatePrice) ?? 0);

                    _MasterProductResult.Sequence      = _Item.Sequence;
                    _MasterProductResult.IsActive      = _Item.IsActive;
                    _MasterProductResult.EnterById     = _Item.EnterById;
                    _MasterProductResult.EnterDate     = _Item.EnterDate;
                    _MasterProductResult.ModifiedById  = _Item.ModifiedById;
                    _MasterProductResult.ModifiedDate  = _Item.ModifiedDate;
                    _MasterProductResult.MaxProductSKU = _Context.ASMasterProductChilds.Where(a => a.MasterProductId == _Item.MasterProductId).Max(a => a.ProductChildSKU);

                    objMasterProductResultList.Add(_MasterProductResult);

                    var _dataChild = (from MPC in _Context.ASMasterProductChilds
                                      join MAA in _Context.ASMasterAssetsAssignments on MPC.MasterProductChildId equals MAA.MasterProductChildId into MAAGroup
                                      from MAA in MAAGroup.DefaultIfEmpty()
                                      where MPC.MasterProductId == _Item.MasterProductId
                                      select new
                    {
                        MPC.MasterProductChildId,
                        MPC.MasterProductId,
                        MPC.ProductChildSKU,
                        MPC.ManufacturerPartNumber,
                        MPC.PurchaseDate,
                        MPC.PurchasePrice,
                        MPC.DepreciatePrice,
                        MPC.WarrantyExpiryDate,
                        MPC.WarrantyStartDate,
                        MPC.IterationOfWarranty,
                        MPC.MasterBranchId,
                        MPC.MasterEmployeeId,
                        MPC.MasterVendorId,
                        MPC.IsDeadAssets,
                        MPC.IsSaleProduct,
                        MPC.IsActive,
                        MasterAssetsAssignmentId = (MAA.MasterAssetsAssignmentId != null ? MAA.MasterAssetsAssignmentId : 0),
                        MAA.AssetsAssignmentDate,
                        MAA.IsAssetsDeAssign
                    });


                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    List <MasterProductAssignChildResult> objMasterProductAssignChildResultList = new List <MasterProductAssignChildResult>();
                    foreach (var _ItemChild in _dataChild.ToList())
                    {
                        MasterProductAssignChildResult _MasterProductAssignChildResult = new MasterProductAssignChildResult();

                        _MasterProductAssignChildResult.MasterProductChildId   = _ItemChild.MasterProductChildId;
                        _MasterProductAssignChildResult.MasterProductId        = _ItemChild.MasterProductId;
                        _MasterProductAssignChildResult.ProductChildSKU        = _ItemChild.ProductChildSKU;
                        _MasterProductAssignChildResult.ManufacturerPartNumber = _ItemChild.ManufacturerPartNumber;
                        _MasterProductAssignChildResult.PurchaseDate           = _ItemChild.PurchaseDate;
                        _MasterProductAssignChildResult.PurchasePrice          = _ItemChild.PurchasePrice;
                        _MasterProductAssignChildResult.DepreciatePrice        = _ItemChild.DepreciatePrice;
                        _MasterProductAssignChildResult.WarrantyExpiryDate     = _ItemChild.WarrantyExpiryDate;
                        _MasterProductAssignChildResult.WarrantyStartDate      = _ItemChild.WarrantyStartDate;
                        _MasterProductAssignChildResult.IterationOfWarranty    = _ItemChild.IterationOfWarranty;
                        _MasterProductAssignChildResult.IsActive                 = _ItemChild.IsActive;
                        _MasterProductAssignChildResult.IsDeadAssets             = _ItemChild.IsDeadAssets;
                        _MasterProductAssignChildResult.IsSaleProduct            = _ItemChild.IsSaleProduct;
                        _MasterProductAssignChildResult.MasterBranchId           = _ItemChild.MasterBranchId;
                        _MasterProductAssignChildResult.BranchTitle              = _AdminBranches.Where(a => a.MasterBranchId == _ItemChild.MasterBranchId).Select(a => a.BranchTitle).FirstOrDefault();
                        _MasterProductAssignChildResult.MasterEmployeeId         = _ItemChild.MasterEmployeeId;
                        _MasterProductAssignChildResult.EmployeeName             = _AdminEmployees.Where(a => a.MasterEmployeeId == _ItemChild.MasterEmployeeId).Select(a => a.EmployeeName).FirstOrDefault();
                        _MasterProductAssignChildResult.MasterAssetsAssignmentId = _ItemChild.MasterAssetsAssignmentId;
                        _MasterProductAssignChildResult.AssetsAssignmentDate     = _ItemChild.AssetsAssignmentDate;
                        _MasterProductAssignChildResult.MasterVendorId           = _ItemChild.MasterVendorId;
                        _MasterProductAssignChildResult.VendorTitle              = _AdminVendors.Where(a => a.MasterVendorId == _ItemChild.MasterVendorId).Select(a => a.VendorTitle).FirstOrDefault();;
                        _MasterProductAssignChildResult.IsAssetsDeAssign         = _ItemChild.IsAssetsDeAssign;

                        objMasterProductAssignChildResultList.Add(_MasterProductAssignChildResult);
                    }
                    _MasterProductResult.ProductAssignChildList = objMasterProductAssignChildResultList;
                }

                return(objMasterProductResultList);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public MasterAssetsAssignmentResult GetASMasterAssetsAssignmentByID(long MasterAssetsAssignmentId)
        {
            try
            {
                var _data = (from MP in _Context.ASMasterProducts
                             //join CO in _AdminContext.ADMasterCountries on MP.CountryOfOrigin equals CO.MasterCountryId into COGroup
                             //from CO in COGroup.DefaultIfEmpty()
                             //join MT in _AdminContext.ADMasterTaxes on MP.ProductTaxCode equals MT.MasterTaxId into MTGroup
                             //from MT in MTGroup.DefaultIfEmpty()
                             //join MC in _AdminContext.ADMasterCurrencies on MP.ProductCurrency equals MC.MasterCurrencyId into MCGroup
                             //from MC in MCGroup.DefaultIfEmpty()
                             join MB in _Context.ASMasterBrands on MP.MasterBrandId equals MB.MasterBrandId into MBGroup
                             from MB in MBGroup.DefaultIfEmpty()
                             join SC in _Context.ASMasterSubCategories on MP.MasterSubCategoryId equals SC.MasterSubCategoryId into SCGroup
                             from SC in SCGroup.DefaultIfEmpty()
                             join CA in _Context.ASMasterCategories on SC.MasterCategoryId equals CA.MasterCategoryId into CAGroup
                             from CA in CAGroup.DefaultIfEmpty()
                             join MPC in _Context.ASMasterProductChilds on MP.MasterProductId equals MPC.MasterProductId
                             join MAA in _Context.ASMasterAssetsAssignments on MPC.MasterProductChildId equals MAA.MasterProductChildId
                             where MAA.MasterAssetsAssignmentId == MasterAssetsAssignmentId
                             select new
                {
                    MPC.MasterProductChildId,
                    MPC.MasterProductId,
                    MPC.ProductChildSKU,
                    MPC.ProductChildTitle,
                    MPC.ManufacturerPartNumber,
                    MPC.PurchaseDate,
                    MPC.PurchasePrice,
                    MPC.DepreciatePrice,
                    MPC.MasterVendorId,
                    MPC.IsDeadAssets,
                    MPC.IsTimeToSaleProduct,
                    MPC.IsSaleProduct,
                    MPC.SaleDate,
                    MPC.SalePrice,
                    MPC.ProductQty,
                    MPC.ProductQtyUnit,
                    MPC.NumberOfItemIncludeInProduct,
                    MPC.ItemPackageQuantity,
                    MPC.IterationOfWarranty,
                    MPC.WarrantyStartDate,
                    MPC.WarrantyExpiryDate,
                    MPC.MasterBranchId,

                    MP.ProductTitle,
                    MP.ProductSKU,
                    MP.MasterSubCategoryId,
                    SC.SubCategoryTitle,
                    MP.MasterBrandId,
                    MB.BrandTitle,
                    CA.MasterCategoryId,
                    CA.CategoryTitle,
                    MP.DepreciatePercentage,
                    MP.ReorderLevel,
                    MP.ProductModel,
                    MP.Manufacturer,

                    MAA.MasterAssetsAssignmentId,
                    MAA.AssetsAssignmentDate,
                    MAA.ASMasterProductChilds,
                    MAA.MasterEmployeeId,
                    MAA.IsAssetsDeAssign,
                    MAA.AssetsDeAssignmentDate,
                    MAA.DeAssignReason,
                    MAA.MasterLocationId,
                    MAA.Sequence,
                    MAA.IsActive,
                    MAA.EnterById,
                    MAA.EnterDate,
                    MAA.ModifiedById,
                    MAA.ModifiedDate,
                });


                var _Item = _data.FirstOrDefault();

                MasterAssetsAssignmentResult _MasterAssetsAssignmentResult = new MasterAssetsAssignmentResult();
                if (_data != null)
                {
                    _MasterAssetsAssignmentResult.MasterAssetsAssignmentId = _Item.MasterAssetsAssignmentId;
                    _MasterAssetsAssignmentResult.AssetsAssignmentDate     = _Item.AssetsAssignmentDate;
                    _MasterAssetsAssignmentResult.MasterEmployeeId         = _Item.MasterEmployeeId;
                    _MasterAssetsAssignmentResult.IsAssetsDeAssign         = _Item.IsAssetsDeAssign;
                    _MasterAssetsAssignmentResult.AssetsDeAssignmentDate   = _Item.AssetsDeAssignmentDate;
                    _MasterAssetsAssignmentResult.DeAssignReason           = _Item.DeAssignReason;
                    _MasterAssetsAssignmentResult.MasterLocationId         = _Item.MasterLocationId;
                    _MasterAssetsAssignmentResult.Sequence     = _Item.Sequence;
                    _MasterAssetsAssignmentResult.IsActive     = _Item.IsActive;
                    _MasterAssetsAssignmentResult.ActiveColor  = "green";
                    _MasterAssetsAssignmentResult.ActiveIcon   = "glyphicon glyphicon-ok";
                    _MasterAssetsAssignmentResult.EnterById    = _Item.EnterById;
                    _MasterAssetsAssignmentResult.EnterDate    = _Item.EnterDate;
                    _MasterAssetsAssignmentResult.ModifiedById = _Item.ModifiedById;
                    _MasterAssetsAssignmentResult.ModifiedDate = _Item.ModifiedDate;

                    if (_MasterAssetsAssignmentResult.IsActive == false)
                    {
                        _MasterAssetsAssignmentResult.ActiveColor = "red";
                        _MasterAssetsAssignmentResult.ActiveIcon  = "glyphicon glyphicon-remove";
                    }

                    _MasterAssetsAssignmentResult.MasterProductChildId = _Item.MasterProductChildId;
                    _MasterAssetsAssignmentResult.MasterProductId      = _Item.MasterProductId;
                    //_MasterAssetsAssignmentResult.ASMasterProducts = _Item.ASMasterProducts;
                    _MasterAssetsAssignmentResult.ProductChildSKU        = _Item.ProductChildSKU;
                    _MasterAssetsAssignmentResult.ProductChildTitle      = _Item.ProductChildTitle;
                    _MasterAssetsAssignmentResult.ManufacturerPartNumber = _Item.ManufacturerPartNumber;
                    //_MasterAssetsAssignmentResult.ASMasterProductSizes = _Item.ASMasterProductSizes;
                    _MasterAssetsAssignmentResult.PurchaseDate                 = _Item.PurchaseDate;
                    _MasterAssetsAssignmentResult.PurchasePrice                = _Item.PurchasePrice;
                    _MasterAssetsAssignmentResult.DepreciatePrice              = _Item.DepreciatePrice;
                    _MasterAssetsAssignmentResult.MasterVendorId               = _Item.MasterVendorId;
                    _MasterAssetsAssignmentResult.IsDeadAssets                 = _Item.IsDeadAssets;
                    _MasterAssetsAssignmentResult.IsTimeToSaleProduct          = _Item.IsTimeToSaleProduct;
                    _MasterAssetsAssignmentResult.IsSaleProduct                = _Item.IsSaleProduct;
                    _MasterAssetsAssignmentResult.SaleDate                     = _Item.SaleDate;
                    _MasterAssetsAssignmentResult.SalePrice                    = _Item.SalePrice;
                    _MasterAssetsAssignmentResult.ProductQty                   = _Item.ProductQty;
                    _MasterAssetsAssignmentResult.ProductQtyUnit               = _Item.ProductQtyUnit;
                    _MasterAssetsAssignmentResult.NumberOfItemIncludeInProduct = _Item.NumberOfItemIncludeInProduct;
                    _MasterAssetsAssignmentResult.ItemPackageQuantity          = _Item.ItemPackageQuantity;
                    _MasterAssetsAssignmentResult.IterationOfWarranty          = _Item.IterationOfWarranty;
                    _MasterAssetsAssignmentResult.WarrantyStartDate            = _Item.WarrantyStartDate;
                    _MasterAssetsAssignmentResult.WarrantyExpiryDate           = _Item.WarrantyExpiryDate;
                    _MasterAssetsAssignmentResult.MasterBranchId               = _Item.MasterBranchId;
                    _MasterAssetsAssignmentResult.MasterEmployeeId             = _Item.MasterEmployeeId;

                    _MasterAssetsAssignmentResult.ProductTitle         = _Item.ProductTitle;
                    _MasterAssetsAssignmentResult.MasterBrandId        = _Item.MasterBrandId;
                    _MasterAssetsAssignmentResult.BrandTitle           = _Item.BrandTitle;
                    _MasterAssetsAssignmentResult.MasterSubCategoryId  = _Item.MasterSubCategoryId;
                    _MasterAssetsAssignmentResult.SubCategoryTitle     = _Item.SubCategoryTitle;
                    _MasterAssetsAssignmentResult.MasterCategoryId     = _Item.MasterCategoryId;
                    _MasterAssetsAssignmentResult.CategoryTitle        = _Item.CategoryTitle;
                    _MasterAssetsAssignmentResult.ProductSKU           = _Item.ProductSKU;
                    _MasterAssetsAssignmentResult.ProductModel         = _Item.ProductModel;
                    _MasterAssetsAssignmentResult.Manufacturer         = _Item.Manufacturer;
                    _MasterAssetsAssignmentResult.DepreciatePercentage = _Item.DepreciatePercentage;
                    _MasterAssetsAssignmentResult.ReorderLevel         = _Item.ReorderLevel;
                }
                return(_MasterAssetsAssignmentResult);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 3
0
        public IEnumerable <MasterProductResult> GetAllASMasterProduct()
        {
            try
            {
                var _data = (from MP in _Context.ASMasterProducts
                             join MB in _Context.ASMasterBrands on MP.MasterBrandId equals MB.MasterBrandId into MBGroup
                             from MB in MBGroup.DefaultIfEmpty()
                             join SC in _Context.ASMasterSubCategories on MP.MasterSubCategoryId equals SC.MasterSubCategoryId into SCGroup
                             from SC in SCGroup.DefaultIfEmpty()
                             join CA in _Context.ASMasterCategories on SC.MasterCategoryId equals CA.MasterCategoryId into CAGroup
                             from CA in CAGroup.DefaultIfEmpty()
                             select new
                {
                    MP.MasterProductId,
                    MP.ProductTitle,
                    MP.ProductSKU,
                    MP.ProductHSNCode,
                    MP.ProductBarCode,
                    MP.ProductMainImage,
                    MP.Description,
                    MP.Specification,
                    MP.LegalDisclamer,
                    MP.SafetyWarning,
                    MP.ProductModel,
                    MP.Manufacturer,
                    MP.DepreciatePercentage,
                    MP.ReorderLevel,
                    MP.CountryOfOrigin,
                    //CO.CountryTitle,
                    MP.ProductTaxCode,
                    //MT.TaxTitle,
                    //MT.IsTaxPercentageAmount,
                    //MT.TaxValue,
                    MP.ProductCurrency,
                    //MC.CurrencyTitle,
                    MP.Sequence,
                    MP.IsActive,
                    MP.EnterById,
                    MP.EnterDate,
                    MP.ModifiedById,
                    MP.ModifiedDate,
                    MP.MasterBrandId,
                    MB.BrandTitle,
                    MP.MasterSubCategoryId,
                    SC.SubCategoryTitle,
                    CA.CategoryTitle,
                    CA.MasterCategoryId
                    //TotalAssets = 2,
                    //AssetsAllocated = 1
                }).ToList();

                var _Productdata = (from MC in _Context.ASMasterCategories
                                    join MSC in _Context.ASMasterSubCategories on MC.MasterCategoryId equals MSC.MasterCategoryId
                                    join MP in _Context.ASMasterProducts on MSC.MasterSubCategoryId equals MP.MasterSubCategoryId into MPGroup
                                    from MP in MPGroup.DefaultIfEmpty()
                                    join MPC in _Context.ASMasterProductChilds on MP.MasterProductId equals MPC.MasterProductId into MPCGroup
                                    from MPC in MPCGroup.DefaultIfEmpty()
                                    select new
                {
                    MC.MasterCategoryId,
                    MC.CategoryTitle,
                    MSC.MasterSubCategoryId,
                    MSC.SubCategoryTitle,
                    MPC.MasterProductId,
                    MPC.ProductChildTitle,
                    MPC.ProductChildSKU,
                    MPC.ManufacturerPartNumber,
                    MPC.PurchasePrice,
                    MPC.DepreciatePrice,
                    MPC.IsActive,
                    MPC.IsDeadAssets,
                    MPC.IsSaleProduct,
                    MPC.MasterBranchId,
                    MPC.MasterEmployeeId,
                    MPC.WarrantyExpiryDate
                });

                var _AdminCountries  = _AdminContext.ADMasterCountries.ToList();
                var _AdminTaxes      = _AdminContext.ADMasterTaxes.ToList();
                var _AdminCurrencies = _AdminContext.ADMasterCurrencies.ToList();

                List <MasterProductResult> objMasterProductResultList = new List <MasterProductResult>();

                foreach (var _Item in _data.ToList())
                {
                    var _MasterProductResult = new MasterProductResult();

                    _MasterProductResult.MasterProductId      = _Item.MasterProductId;
                    _MasterProductResult.ProductTitle         = _Item.ProductTitle;
                    _MasterProductResult.MasterBrandId        = _Item.MasterBrandId;
                    _MasterProductResult.BrandTitle           = _Item.BrandTitle;
                    _MasterProductResult.MasterSubCategoryId  = _Item.MasterSubCategoryId;
                    _MasterProductResult.SubCategoryTitle     = _Item.SubCategoryTitle;
                    _MasterProductResult.MasterCategoryId     = _Item.MasterCategoryId;
                    _MasterProductResult.CategoryTitle        = _Item.CategoryTitle;
                    _MasterProductResult.ProductSKU           = _Item.ProductSKU;
                    _MasterProductResult.ProductHSNCode       = _Item.ProductHSNCode;
                    _MasterProductResult.ProductBarCode       = _Item.ProductBarCode;
                    _MasterProductResult.ProductMainImage     = _Item.ProductMainImage;
                    _MasterProductResult.Description          = _Item.Description;
                    _MasterProductResult.Specification        = _Item.Specification;
                    _MasterProductResult.LegalDisclamer       = _Item.LegalDisclamer;
                    _MasterProductResult.SafetyWarning        = _Item.SafetyWarning;
                    _MasterProductResult.ProductModel         = _Item.ProductModel;
                    _MasterProductResult.Manufacturer         = _Item.Manufacturer;
                    _MasterProductResult.DepreciatePercentage = _Item.DepreciatePercentage;
                    _MasterProductResult.ReorderLevel         = _Item.ReorderLevel;
                    _MasterProductResult.CountryOfOrigin      = _Item.CountryOfOrigin;
                    _MasterProductResult.CountryOfOriginTitle = _AdminCountries.Where(a => a.MasterCountryId == _Item.CountryOfOrigin).Select(a => a.CountryTitle).FirstOrDefault();
                    _MasterProductResult.ProductTaxCode       = _Item.ProductTaxCode;
                    _MasterProductResult.ProductTaxCodeTitle  = _AdminTaxes.Where(a => a.MasterTaxId == _Item.ProductTaxCode).Select(a => a.TaxTitle).FirstOrDefault();
                    _MasterProductResult.ProductCurrency      = _Item.ProductCurrency;
                    _MasterProductResult.ProductCurrencyTitle = _AdminCurrencies.Where(a => a.MasterCurrencyId == _Item.ProductCurrency).Select(a => a.CurrencyTitle).FirstOrDefault();;
                    _MasterProductResult.Sequence             = _Item.Sequence;

                    _MasterProductResult.TotalAssetsInStock          = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == true && a.IsDeadAssets == false && a.IsSaleProduct == false).Count());
                    _MasterProductResult.AssetsAssign                = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == true && a.IsDeadAssets == false && a.IsSaleProduct == false && (a.MasterEmployeeId != 0)).Count());
                    _MasterProductResult.AssetsInRepair              = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == false && a.IsDeadAssets == false && a.IsSaleProduct == false).Count());
                    _MasterProductResult.ServiceInExpire             = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.WarrantyExpiryDate <= DateTime.Now && a.IsActive == true && a.IsDeadAssets == false && a.IsSaleProduct == false).Count());
                    _MasterProductResult.AssetsInSold                = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == false && a.IsDeadAssets == false && a.IsSaleProduct == true).Count());
                    _MasterProductResult.AssetsInDead                = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsActive == false && a.IsDeadAssets == true && a.IsSaleProduct == false).Count());
                    _MasterProductResult.TotalAssetsCost             = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsDeadAssets == false && a.IsSaleProduct == false).Sum(a => a.PurchasePrice) ?? 0);
                    _MasterProductResult.TotalAssetsDepreciatedValue = (_Productdata.Where(a => a.MasterProductId == _Item.MasterProductId && a.IsDeadAssets == false && a.IsSaleProduct == false).Sum(a => a.DepreciatePrice) ?? 0);


                    _MasterProductResult.IsActive     = _Item.IsActive;
                    _MasterProductResult.EnterById    = _Item.EnterById;
                    _MasterProductResult.EnterDate    = _Item.EnterDate;
                    _MasterProductResult.ModifiedById = _Item.ModifiedById;
                    _MasterProductResult.ModifiedDate = _Item.ModifiedDate;

                    objMasterProductResultList.Add(_MasterProductResult);
                }
                return(objMasterProductResultList.ToList());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IEnumerable <MasterAssetsAssignmentResult> GetAllASMasterAssetsAssignment(long MasterEmployeeId)
        {
            try
            {
                var _data = (from MP in _Context.ASMasterProducts
                             join MB in _Context.ASMasterBrands on MP.MasterBrandId equals MB.MasterBrandId into MBGroup
                             from MB in MBGroup.DefaultIfEmpty()
                             join SC in _Context.ASMasterSubCategories on MP.MasterSubCategoryId equals SC.MasterSubCategoryId into SCGroup
                             from SC in SCGroup.DefaultIfEmpty()
                             join CA in _Context.ASMasterCategories on SC.MasterCategoryId equals CA.MasterCategoryId into CAGroup
                             from CA in CAGroup.DefaultIfEmpty()
                             join MPC in _Context.ASMasterProductChilds on MP.MasterProductId equals MPC.MasterProductId
                             join MAA in _Context.ASMasterAssetsAssignments on MPC.MasterProductChildId equals MAA.MasterProductChildId
                             where MAA.MasterEmployeeId == MasterEmployeeId
                             select new
                {
                    MPC.MasterProductChildId,
                    MPC.MasterProductId,
                    MPC.ProductChildSKU,
                    MPC.ProductChildTitle,
                    MPC.ManufacturerPartNumber,
                    MPC.PurchaseDate,
                    MPC.PurchasePrice,
                    MPC.DepreciatePrice,
                    MPC.MasterVendorId,
                    MPC.IsDeadAssets,
                    MPC.IsTimeToSaleProduct,
                    MPC.IsSaleProduct,
                    MPC.SaleDate,
                    MPC.SalePrice,
                    MPC.ProductQty,
                    MPC.ProductQtyUnit,
                    MPC.NumberOfItemIncludeInProduct,
                    MPC.ItemPackageQuantity,
                    MPC.IterationOfWarranty,
                    MPC.WarrantyStartDate,
                    MPC.WarrantyExpiryDate,
                    MPC.MasterBranchId,

                    MP.ProductTitle,
                    MP.ProductSKU,
                    MP.MasterSubCategoryId,
                    SC.SubCategoryTitle,
                    MP.MasterBrandId,
                    MB.BrandTitle,
                    CA.MasterCategoryId,
                    CA.CategoryTitle,
                    MP.DepreciatePercentage,
                    MP.ReorderLevel,
                    MP.ProductModel,
                    MP.Manufacturer,


                    MAA.MasterAssetsAssignmentId,
                    MAA.AssetsAssignmentDate,
                    MAA.ASMasterProductChilds,
                    MAA.MasterEmployeeId,
                    MAA.IsAssetsDeAssign,
                    MAA.AssetsDeAssignmentDate,
                    MAA.DeAssignReason,
                    MAA.MasterLocationId,
                    MAA.Sequence,
                    MAA.IsActive,
                    MAA.EnterById,
                    MAA.EnterDate,
                    MAA.ModifiedById,
                    MAA.ModifiedDate,
                });

                List <MasterAssetsAssignmentResult> objMasterAssetsAssignmentResultList = new List <MasterAssetsAssignmentResult>();

                foreach (var _Item in _data.ToList())
                {
                    var _MasterAssetsAssignmentResult = new MasterAssetsAssignmentResult();


                    _MasterAssetsAssignmentResult.MasterAssetsAssignmentId = _Item.MasterAssetsAssignmentId;
                    _MasterAssetsAssignmentResult.AssetsAssignmentDate     = _Item.AssetsAssignmentDate;
                    _MasterAssetsAssignmentResult.MasterEmployeeId         = _Item.MasterEmployeeId;
                    _MasterAssetsAssignmentResult.IsAssetsDeAssign         = _Item.IsAssetsDeAssign;
                    _MasterAssetsAssignmentResult.AssetsDeAssignmentDate   = _Item.AssetsDeAssignmentDate;
                    _MasterAssetsAssignmentResult.DeAssignReason           = _Item.DeAssignReason;
                    _MasterAssetsAssignmentResult.MasterLocationId         = _Item.MasterLocationId;
                    _MasterAssetsAssignmentResult.Sequence     = _Item.Sequence;
                    _MasterAssetsAssignmentResult.IsActive     = _Item.IsActive;
                    _MasterAssetsAssignmentResult.ActiveColor  = "green";
                    _MasterAssetsAssignmentResult.ActiveIcon   = "glyphicon glyphicon-ok";
                    _MasterAssetsAssignmentResult.EnterById    = _Item.EnterById;
                    _MasterAssetsAssignmentResult.EnterDate    = _Item.EnterDate;
                    _MasterAssetsAssignmentResult.ModifiedById = _Item.ModifiedById;
                    _MasterAssetsAssignmentResult.ModifiedDate = _Item.ModifiedDate;

                    if (_MasterAssetsAssignmentResult.IsActive == false)
                    {
                        _MasterAssetsAssignmentResult.ActiveColor = "red";
                        _MasterAssetsAssignmentResult.ActiveIcon  = "glyphicon glyphicon-remove";
                    }

                    _MasterAssetsAssignmentResult.MasterProductChildId = _Item.MasterProductChildId;
                    _MasterAssetsAssignmentResult.MasterProductId      = _Item.MasterProductId;
                    //_MasterAssetsAssignmentResult.ASMasterProducts = _Item.ASMasterProducts;
                    _MasterAssetsAssignmentResult.ProductChildSKU        = _Item.ProductChildSKU;
                    _MasterAssetsAssignmentResult.ProductChildTitle      = _Item.ProductChildTitle;
                    _MasterAssetsAssignmentResult.ManufacturerPartNumber = _Item.ManufacturerPartNumber;
                    //_MasterAssetsAssignmentResult.ASMasterProductSizes = _Item.ASMasterProductSizes;
                    _MasterAssetsAssignmentResult.PurchaseDate                 = _Item.PurchaseDate;
                    _MasterAssetsAssignmentResult.PurchasePrice                = _Item.PurchasePrice;
                    _MasterAssetsAssignmentResult.DepreciatePrice              = _Item.DepreciatePrice;
                    _MasterAssetsAssignmentResult.MasterVendorId               = _Item.MasterVendorId;
                    _MasterAssetsAssignmentResult.IsDeadAssets                 = _Item.IsDeadAssets;
                    _MasterAssetsAssignmentResult.IsTimeToSaleProduct          = _Item.IsTimeToSaleProduct;
                    _MasterAssetsAssignmentResult.IsSaleProduct                = _Item.IsSaleProduct;
                    _MasterAssetsAssignmentResult.SaleDate                     = _Item.SaleDate;
                    _MasterAssetsAssignmentResult.SalePrice                    = _Item.SalePrice;
                    _MasterAssetsAssignmentResult.ProductQty                   = _Item.ProductQty;
                    _MasterAssetsAssignmentResult.ProductQtyUnit               = _Item.ProductQtyUnit;
                    _MasterAssetsAssignmentResult.NumberOfItemIncludeInProduct = _Item.NumberOfItemIncludeInProduct;
                    _MasterAssetsAssignmentResult.ItemPackageQuantity          = _Item.ItemPackageQuantity;
                    _MasterAssetsAssignmentResult.IterationOfWarranty          = _Item.IterationOfWarranty;
                    _MasterAssetsAssignmentResult.WarrantyStartDate            = _Item.WarrantyStartDate;
                    _MasterAssetsAssignmentResult.WarrantyExpiryDate           = _Item.WarrantyExpiryDate;
                    _MasterAssetsAssignmentResult.MasterBranchId               = _Item.MasterBranchId;
                    _MasterAssetsAssignmentResult.MasterEmployeeId             = _Item.MasterEmployeeId;
                    _MasterAssetsAssignmentResult.EmployeeName                 = "";
                    _MasterAssetsAssignmentResult.ProductTitle                 = _Item.ProductTitle;
                    _MasterAssetsAssignmentResult.MasterBrandId                = _Item.MasterBrandId;
                    _MasterAssetsAssignmentResult.BrandTitle                   = _Item.BrandTitle;
                    _MasterAssetsAssignmentResult.MasterSubCategoryId          = _Item.MasterSubCategoryId;
                    _MasterAssetsAssignmentResult.SubCategoryTitle             = _Item.SubCategoryTitle;
                    _MasterAssetsAssignmentResult.MasterCategoryId             = _Item.MasterCategoryId;
                    _MasterAssetsAssignmentResult.CategoryTitle                = _Item.CategoryTitle;
                    _MasterAssetsAssignmentResult.ProductSKU                   = _Item.ProductSKU;
                    _MasterAssetsAssignmentResult.ProductModel                 = _Item.ProductModel;
                    _MasterAssetsAssignmentResult.Manufacturer                 = _Item.Manufacturer;
                    _MasterAssetsAssignmentResult.DepreciatePercentage         = _Item.DepreciatePercentage;
                    _MasterAssetsAssignmentResult.ReorderLevel                 = _Item.ReorderLevel;

                    objMasterAssetsAssignmentResultList.Add(_MasterAssetsAssignmentResult);
                }
                return(objMasterAssetsAssignmentResultList);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }