简体   繁体   English

登录后是否从其他连接中检索数据?

[英]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. 我的mvc应用程序中有两个数据连接。

DeafultConnection which contains aspnetusers which I am using for user logins and Registrations. DeafultConnection包含我用于用户登录和注册的aspnetusers。

Then LotusWorksEntities which I am using to track Employee details such as holiday requests, hours taking etc. 然后是我用来跟踪员工详细信息(例如假期请求,工作时间等)的LotusWorksEntities。

In DefaultConnections under aspnetusers, there's a column for email. 在aspnetusers下的DefaultConnections中,有一列用于发送电子邮件。 In LotusWorksEntitles under Employee Table, there's also a column for email. 在“员工表”下的LotusWorksEntitles中,还有一个电子邮件列。

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. 员工表和站点表通过外键连接。

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#. 但是无论如何,您都可以使用Linq联接来连接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. 这里说明了如何在内存中连接两个列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM