public bool SaveAgentDistributorClassDeal(int?agentClassId, int?masterDealId, int?hotelMasterDealId, int?busMasterDealId, int?mobileMasterDealId, int appUserId, int distributorID)
        {
            if (masterDealId != null)
            {
                if (!IsDistributorAirlineDealInserted(agentClassId, distributorID))
                {
                    AgentClassDeals obj = new AgentClassDeals
                    {
                        AgentClassId  = agentClassId ?? 0,
                        DealMasterId  = masterDealId ?? 0,
                        CreatedBy     = appUserId,
                        CreatedDate   = DateTime.Now,
                        DistributorId = distributorID
                    };
                    ent.AddToAgentClassDeals(obj);
                }
                else
                {
                    if (!IsDistributorSameMasterDealAlreadyExists(agentClassId, masterDealId, distributorID))
                    {
                        var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                        foreach (var delete in objToDelete)
                        {
                            int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                            if (productId == 1)
                            {
                                ent.DeleteObject(delete);
                            }
                        }
                        AgentClassDeals obj = new AgentClassDeals
                        {
                            AgentClassId  = agentClassId ?? 0,
                            DealMasterId  = masterDealId ?? 0,
                            CreatedBy     = appUserId,
                            CreatedDate   = DateTime.Now,
                            DistributorId = distributorID
                        };
                        ent.AddToAgentClassDeals(obj);
                    }
                }
            }
            else
            {
                var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId && z.DistributorId == distributorID);
                foreach (var delete in objToDelete)
                {
                    int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                    if (productId == 1)
                    {
                        ent.DeleteObject(delete);
                    }
                }
            }

            if (hotelMasterDealId != null)
            {
                if (!IsDistributorHotelDealInserted(agentClassId, distributorID))
                {
                    AgentClassDeals obj = new AgentClassDeals
                    {
                        AgentClassId  = agentClassId ?? 0,
                        DealMasterId  = hotelMasterDealId ?? 0,
                        CreatedBy     = appUserId,
                        CreatedDate   = DateTime.Now,
                        DistributorId = distributorID
                    };
                    ent.AddToAgentClassDeals(obj);
                }
                else
                {
                    if (!IsDistributorSameMasterDealAlreadyExists(agentClassId, hotelMasterDealId, distributorID))
                    {
                        var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                        foreach (var delete in objToDelete)
                        {
                            int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                            if (productId == 2)
                            {
                                ent.DeleteObject(delete);
                            }
                        }
                        AgentClassDeals obj = new AgentClassDeals
                        {
                            AgentClassId  = agentClassId ?? 0,
                            DealMasterId  = hotelMasterDealId ?? 0,
                            CreatedBy     = appUserId,
                            CreatedDate   = DateTime.Now,
                            DistributorId = distributorID
                        };
                        ent.AddToAgentClassDeals(obj);
                    }
                }
            }
            else
            {
                var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                foreach (var delete in objToDelete)
                {
                    int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                    if (productId == 2)
                    {
                        ent.DeleteObject(delete);
                    }
                }
            }


            if (busMasterDealId != null)
            {
                if (!IsDistributorBusDealInserted(agentClassId, distributorID))
                {
                    AgentClassDeals obj = new AgentClassDeals
                    {
                        AgentClassId  = agentClassId ?? 0,
                        DealMasterId  = busMasterDealId ?? 0,
                        CreatedBy     = appUserId,
                        CreatedDate   = DateTime.Now,
                        DistributorId = distributorID
                    };
                    ent.AddToAgentClassDeals(obj);
                }
                else
                {
                    if (!IsDistributorSameMasterDealAlreadyExists(agentClassId, busMasterDealId, distributorID))
                    {
                        var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                        foreach (var delete in objToDelete)
                        {
                            int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                            if (productId == 4)
                            {
                                ent.DeleteObject(delete);
                            }
                        }
                        AgentClassDeals obj = new AgentClassDeals
                        {
                            AgentClassId  = agentClassId ?? 0,
                            DealMasterId  = busMasterDealId ?? 0,
                            CreatedBy     = appUserId,
                            CreatedDate   = DateTime.Now,
                            DistributorId = distributorID
                        };
                        ent.AddToAgentClassDeals(obj);
                    }
                }
            }
            else
            {
                var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                foreach (var delete in objToDelete)
                {
                    int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                    if (productId == 4)
                    {
                        ent.DeleteObject(delete);
                    }
                }
            }



            if (mobileMasterDealId != null)
            {
                if (!IsDistributorMobileDealInserted(agentClassId, distributorID))
                {
                    AgentClassDeals obj = new AgentClassDeals
                    {
                        AgentClassId  = agentClassId ?? 0,
                        DealMasterId  = mobileMasterDealId ?? 0,
                        CreatedBy     = appUserId,
                        CreatedDate   = DateTime.Now,
                        DistributorId = distributorID
                    };
                    ent.AddToAgentClassDeals(obj);
                }
                else
                {
                    if (!IsDistributorSameMasterDealAlreadyExists(agentClassId, mobileMasterDealId, distributorID))
                    {
                        var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                        foreach (var delete in objToDelete)
                        {
                            int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                            if (productId == 3)
                            {
                                ent.DeleteObject(delete);
                            }
                        }
                        AgentClassDeals obj = new AgentClassDeals
                        {
                            AgentClassId  = agentClassId ?? 0,
                            DealMasterId  = mobileMasterDealId ?? 0,
                            CreatedBy     = appUserId,
                            CreatedDate   = DateTime.Now,
                            DistributorId = distributorID
                        };
                        ent.AddToAgentClassDeals(obj);
                    }
                }
            }
            else
            {
                var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                foreach (var delete in objToDelete)
                {
                    int productId = GetProductIdByDistributorMasterDealId(delete.DealMasterId);
                    if (productId == 3)
                    {
                        ent.DeleteObject(delete);
                    }
                }
            }



            ent.SaveChanges();
            return(true);
        }
        public bool SaveAgentClassDeal(int?agentClassId, int?masterDealId, int?hotelMasterDealId, int appUserId)
        {
            if (masterDealId != null)
            {
                if (!IsAirlineDealInserted(agentClassId))
                {
                    AgentClassDeals obj = new AgentClassDeals
                    {
                        AgentClassId = agentClassId ?? 0,
                        DealMasterId = masterDealId ?? 0,
                        CreatedBy    = appUserId,
                        CreatedDate  = DateTime.Now
                    };
                    ent.AddToAgentClassDeals(obj);
                }
                else
                {
                    if (!IsSameMasterDealAlreadyExists(agentClassId, masterDealId))
                    {
                        var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                        foreach (var delete in objToDelete)
                        {
                            int productId = GetProductIdByMasterDealId(delete.DealMasterId);
                            if (productId == 1)
                            {
                                ent.DeleteObject(delete);
                            }
                        }
                        AgentClassDeals obj = new AgentClassDeals
                        {
                            AgentClassId = agentClassId ?? 0,
                            DealMasterId = masterDealId ?? 0,
                            CreatedBy    = appUserId,
                            CreatedDate  = DateTime.Now
                        };
                        ent.AddToAgentClassDeals(obj);
                    }
                }
            }
            else
            {
                var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                foreach (var delete in objToDelete)
                {
                    int productId = GetProductIdByMasterDealId(delete.DealMasterId);
                    if (productId == 1)
                    {
                        ent.DeleteObject(delete);
                    }
                }
            }

            if (hotelMasterDealId != null)
            {
                if (!IsHotelDealInserted(agentClassId))
                {
                    AgentClassDeals obj = new AgentClassDeals
                    {
                        AgentClassId = agentClassId ?? 0,
                        DealMasterId = hotelMasterDealId ?? 0,
                        CreatedBy    = appUserId,
                        CreatedDate  = DateTime.Now
                    };
                    ent.AddToAgentClassDeals(obj);
                }
                else
                {
                    if (!IsSameMasterDealAlreadyExists(agentClassId, hotelMasterDealId))
                    {
                        var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                        foreach (var delete in objToDelete)
                        {
                            int productId = GetProductIdByMasterDealId(delete.DealMasterId);
                            if (productId == 2)
                            {
                                ent.DeleteObject(delete);
                            }
                        }
                        AgentClassDeals obj = new AgentClassDeals
                        {
                            AgentClassId = agentClassId ?? 0,
                            DealMasterId = hotelMasterDealId ?? 0,
                            CreatedBy    = appUserId,
                            CreatedDate  = DateTime.Now
                        };
                        ent.AddToAgentClassDeals(obj);
                    }
                }
            }
            else
            {
                var objToDelete = ent.AgentClassDeals.Where(z => z.AgentClassId == agentClassId);
                foreach (var delete in objToDelete)
                {
                    int productId = GetProductIdByMasterDealId(delete.DealMasterId);
                    if (productId == 2)
                    {
                        ent.DeleteObject(delete);
                    }
                }
            }
            ent.SaveChanges();
            return(true);
        }