private List<Opportunity> GetopportunitiesByUser(UserModel user)
 {
     OpportunitiesRepository opportunitiesSource = new OpportunitiesRepository();
     List<Opportunity> opportunties = null;
     try
     {
         opportunties = opportunitiesSource.GetOpportunitiesByUser(user.UserId).ToList<Opportunity>();
     }
     catch (Exception ex)
     {
         throw new Exception("exception in UserEntities.Getopportunities: " + ex.Message);
     }
     return opportunties;
 }
        private IEnumerable<TBL_OPPORTUNITIES> Getopportunities(UserModel user)
        {
            OpportunitiesRepository opportunitiesSource = new OpportunitiesRepository();
            IEnumerable<TBL_OPPORTUNITIES> opportunties = null;
            try
            {
                if (user.Role == SandlerRoles.FranchiseeUser)
                    opportunties = opportunitiesSource.GetAll().Where(record => record.IsActive == true && record.CreatedBy.ToLower() == user.UserId.ToString().ToLower()).AsEnumerable();
                else if (user.Role == SandlerRoles.FranchiseeOwner)
                {
                    //opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true)
                    //               from company in companies.Where(record => record.COMPANIESID == opportunity.COMPANYID)
                    //               select opportunity;
                    opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true && record.TBL_COMPANIES.FranchiseeId == user.FranchiseeID)
                                   select opportunity;
                }
                else if (user.Role == SandlerRoles.Coach)
                {
                    FranchiseeRepository franchiseeSource = new FranchiseeRepository();
                    CoachRepository coachSource = new CoachRepository();
                    //opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true)
                    //               from company in companies.Where(record => record.COMPANIESID == opportunity.COMPANYID)
                    //               from franchisee in franchisees.Where(record => record.ID == company.FranchiseeId)
                    //               select opportunity;
                    opportunties = from opportunity in opportunitiesSource.GetAll().Where(record => record.IsActive == true && record.TBL_COMPANIES.TBL_FRANCHISEE.CoachID == user.CoachID)
                                   select opportunity;

                }
                else if (user.Role == SandlerRoles.Corporate)
                {
                    opportunties = opportunitiesSource.GetAll().Where(record => record.IsActive == true).AsEnumerable();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("exception in UserEntities.Getopportunities: " + ex.Message);
            }
            return opportunties;
        }
 protected virtual TBL_OPPORTUNITIES Save(TBL_OPPORTUNITIES opportunity)
 {
     OpportunitiesRepository opportunitySource = new OpportunitiesRepository(); ;
     opportunitySource.Add(opportunity);
     UserEntitiesFactory.ReLoad();
     return opportunity;
 }
 protected virtual TBL_OPPORTUNITIES Update(TBL_OPPORTUNITIES opportunity)
 {
     OpportunitiesRepository opportunitySource = new OpportunitiesRepository();
     opportunitySource.Update(opportunity);
     RefreshEntities();
     return opportunity;
 }
 protected virtual TBL_OPPORTUNITIES GetOpportunity(int id)
 {
     OpportunitiesRepository opportunitySource = new OpportunitiesRepository();
     return opportunitySource.GetById(id);
 }