Conor8630
Conor8630

Reputation: 345

Retrieving data from a different connection after logging in?

I am building a holiday tracking website.

I have two data connections in my mvc application.

DeafultConnection which contains aspnetusers which I am using for user logins and Registrations.

Then LotusWorksEntities which I am using to track Employee details such as holiday requests, hours taking etc.

In DefaultConnections under aspnetusers, there's a column for email. In LotusWorksEntitles under Employee Table, there's also a column for email.

On my Admin view page, I have a list of all Employees which has a column for Site.

I want Admins who have been assigned certain sites to only see employees from those assigned sites.

I have done this manually by

public ActionResult Index()
    {

        var employees = db.Employees.Include(e => e.Area).Include(e => e.Discipline).Include(e => e.Shift).Include(e => e.Site).Where(e => e.SiteID == 2);
        return View(employees.ToList());
    } 

Is there a way that I could connect these two connections, so that when an admin logs in, it knows what site they've been assigned to and displays those employees under that site.

Here are my models:

 public partial class Employee
{
    public int EmployeeID { get; set; }
    public string FullName { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public System.DateTime StartDate { get; set; }
    public int RoleID { get; set; }
    public int ShiftID { get; set; }
    public int AreaID { get; set; }
    public int DisciplineID { get; set; }
    public int SiteID { get; set; }
    public int ALCategory { get; set; }
    public int HoursTaken { get; set; }
    public Nullable<int> AwardedLeave { get; set; }
    public Nullable<int> TotalHoursThisYear { get; set; }
    public int HoursCarriedForward { get; set; }
    public Nullable<int> EntitlementRemainingThisYear { get; set; }
    public string Comments { get; set; }
    public int SickLeaveTaken { get; set; }
    public Nullable<int> SickLeaveEntitlement { get; set; }
    public Nullable<int> SickLeaveEntitlementRemaining { get; set; }
    public int StudyLeaveEntitlement { get; set; }
    public int StudyLeaveTaken { get; set; }
    public Nullable<int> StudyLeaveRemaining { get; set; }
    public int ExamLeaveTaken { get; set; }
    public int ForceMajeure { get; set; }
    public int BereavementLeaveTaken { get; set; }
    public int MaternityLeaveTaken { get; set; }
    public int ParentalLeaveTaken { get; set; }
    public int AdoptionLeaveTaken { get; set; }
    public string ManagerEmail { get; set; }
    public string AreaManagerEmail { get; set; }

    public virtual Area Area { get; set; }
    public virtual Discipline Discipline { get; set; }
    public virtual Shift Shift { get; set; }
    public virtual Site Site { get; set; }
}

Then my Site Model is:

public partial class Site
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Site()
    {
        this.Employees = new HashSet<Employee>();
    }

    public int SiteID { get; set; }
    public string SiteName { get; set; }
    public string SiteManager { get; set; }
    public string SiteDelegate { get; set; }
    public string SiteAdmin { get; set; }
    public string SiteLocation { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Employee> Employees { get; set; }
}

Employee Table and Site Table are connected through a foreign key.

Upvotes: 0

Views: 48

Answers (1)

Krunal Parmar
Krunal Parmar

Reputation: 501

Not completely understood which two connections you have is it database connection you are talking about?

But anyways you can use Linq joins to connect two separate list of objects in C#. filter data. Basically your two list should have some relation for join to work.

Here it is explained how to join two list in memory.

Upvotes: 0

Related Questions