protected virtual void DeleteOpportunityHistory(int id)
    {
        OppHistoryRepository repository;

        try
        {
            repository = new OppHistoryRepository();
            repository.Delete(repository.GetById(id));
            RefreshEntities();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected virtual TBL_OpportunitiesHistory GetOpportunityHistory(int id)
    {
        OppHistoryRepository repository;

        try
        {
            repository = new OppHistoryRepository();
            return repository.GetById(id);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected virtual TBL_OpportunitiesHistory UpdateOpportunityHistory(TBL_OpportunitiesHistory history)
    {
        OppHistoryRepository repository;

        try
        {
            repository = new OppHistoryRepository();
            repository.Update(history);
            RefreshEntities();
            return history;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected virtual object GetOpportunitiesHistory(int companyId, int opportunityId)
    {
        OppHistoryRepository repository;

        try
        {
            repository = new OppHistoryRepository();
            var data = from history in repository.GetAll().Where(record => record.CompanyID == companyId && record.OpportunityID == opportunityId)
                       from users in new UsersRepository().GetAll().Where(user => user.UserId == history.CreatedBy)
                       select new { ID=history.ID, Notes = history.Notes, CreatedBy = users.UserName, CreatedDate = history.CreatedDate };

            return data;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }