public bool SaveAndUpdateCustomerMaterial(IList<CustomerMaterialMapDTO> listCustomerMaterial)
        {     
            foreach (CustomerMaterialMapDTO item in listCustomerMaterial)
            {
                customermaterialmap custMaterialMapEntity = new customermaterialmap();

                CustomerMaterialMapDTO custMaterialMap = GetCustomerMaterialByCustomerAndMaterialId(item.Cust_Mat_CustId,
                    item.Cust_Mat_MaterialId);

                if (custMaterialMap.Cust_Mat_Id > 0)
                {
                    AutoMapper.Mapper.Map(custMaterialMap, custMaterialMapEntity);
                    custMaterialMapEntity.Cust_Mat_AllotedQuantityId = item.Cust_Mat_AllotedQuantityId;
                    custMaterialMapEntity.Cust_Mat_LiftingLimit = item.Cust_Mat_LiftingLimit;
                    ESalesUnityContainer.Container.Resolve<IGenericRepository<customermaterialmap>>().Update(custMaterialMapEntity);
                }
                else
                {
                    AutoMapper.Mapper.Map(item, custMaterialMapEntity);
                    ESalesUnityContainer.Container.Resolve<IGenericRepository<customermaterialmap>>().Save(custMaterialMapEntity);
                }
            }
            return true;
        }
    /// <summary>
    /// Updates the lifting interval by business type id.
    /// </summary>
    /// <param name="businessTypeId">The business type id.</param>
    /// <param name="annualLimit">The annual limit.</param>
    /// <param name="liftingLimit">The lifting limit.</param>
    /// <param name="liftingInterval">The lifting interval.</param>
    /// <param name="truckRegId">The truck reg id.</param>
    private void UpdateLiftingIntervalByBusinessTypeId(int businessTypeId, int annualLimit, int liftingLimit, int liftingInterval, int truckRegId)
    {
        List<CustomerMaterialMapDTO> lstCustomerMatDetails = new List<CustomerMaterialMapDTO>();
        List<CustomerMaterialMapDTO> lstCustomerMat = new List<CustomerMaterialMapDTO>();
        List<AllotedQuantityDTO> lstQty = new List<AllotedQuantityDTO>();
        int quantityFlag = 0;
        int qtyId = 0;

        // Update truckregtypeid for business other than bricks
        if (businessTypeId != 1)
        {
            ESalesUnityContainer.Container.Resolve<ILiftingLimit>().UpdateLiftingLimitTruckRegId(truckRegId);
        }

        // Get details of customer by businesstypeid
        List<int> lstCustomer = ESalesUnityContainer.Container.Resolve<ICustomerService>().GetCustomerIdByBusinessTypeId(businessTypeId);
        // Get all customermaterialmap details
        lstCustomerMatDetails = ESalesUnityContainer.Container.Resolve<ICustomerMaterialService>().GetCustomerMaterialDetailsList();

        // Get allotted quantity details
        lstQty = ESalesUnityContainer.Container.Resolve<ILiftingLimit>().GetAllottedQuantityDetails();

        // Check if quantity exists in allotted quantity details
        foreach (AllotedQuantityDTO item in lstQty)
        {
            if (item.Alloted_Quantity == annualLimit.ToString())
            {
                quantityFlag = 1;
                qtyId = item.Alloted_Id;
                break;
            }
        }
        // Will add new entry in allotted quantity if it doesn't exist
        if (quantityFlag != 1)
        {
            AllotedQuantityDTO allottedQty = new AllotedQuantityDTO();

            allottedQty.Alloted_Quantity = annualLimit.ToString();
            allottedQty.Alloted_CreatedBy = GetCurrentUserId();
            allottedQty.Alloted_CreatedDate = DateTime.Now;
            allottedQty.Alloted_IsDeleted = false;

            qtyId = ESalesUnityContainer.Container.Resolve<ILiftingLimit>().InsertAllottedQuantity(allottedQty);
        }

        // Get filtered list of customers based on businesstypeid
        lstCustomerMat = lstCustomerMatDetails.FindAll(C => lstCustomer.Contains(C.Cust_Mat_CustId));

        foreach (CustomerMaterialMapDTO item in lstCustomerMat)
        {
            customermaterialmap upCustomerMatEntity = new customermaterialmap();
            item.Cust_Mat_LiftingLimit = liftingLimit;
            item.Cust_Mat_AllotedQuantityId = qtyId;
            item.Cust_Mat_Timeinterval = liftingInterval;
            item.Cust_Mat_LastUpdatedDate = DateTime.Now;
            AutoMapper.Mapper.Map(item, upCustomerMatEntity);
            ESalesUnityContainer.Container.Resolve<IGenericRepository<customermaterialmap>>().Update(upCustomerMatEntity);
        }
    }
 /// <summary>
 /// Delete Customer Materials
 /// </summary>
 /// <param name="customerMaterials"></param>
 public void DeleteCustomerMaterials(CustomerMaterialMapDTO customerMaterials)
 {
     customermaterialmap customerMaterialMapEntity = new customermaterialmap();
     AutoMapper.Mapper.Map(customerMaterials, customerMaterialMapEntity);
     ESalesUnityContainer.Container.Resolve<IGenericRepository<customermaterialmap>>().Update(customerMaterialMapEntity);
 }