I have Document class:
public class Document
{
public int FromCompanyId { get; set; }
public int ToCompanyId { get; set; }
public string DocumentText { get; set; }
}
When any Company sends Document to others, I saved their Id‘s. Shortly I have many pairs of ID’s:
1, 2 // Company which has Id=1 sent document to Company which has Id=2.
1, 3 // Company which has Id=1 sent document to Company which has Id=3.
4, 3 // Company which has Id=4 sent document to Company which has Id=3 etc.
2, 1
4, 3
4, 5
5, 4
5, 5
4, 5
3, 1
I want to make any Company manage only its own documents. Sent and Received. How can I get documents by Company Id? Or anybody can give another advice.
So, when id = ToCompanyId (any Company sent document to this Company) I want to group by FromCompanyId and when id = FromCompanyId (this Company sent document to other Company) I want to group by ToCompanyId.
This looks like facebook messages. When I cross my messages, I see my all dialogues by Id of other users. In my application I want to see documents by Id of other companies.
This works right only id = FromCompanyId.
GetDocumentsByCompanyId(int Id)
{
...
var myDocs= MyDatabaseContext.Documents.Where(e => e.FromCompanyId == Id|| e.ToCompanyId == Id);
var docGroups = from m in myDocs
group m by m.ToCompanyId
into g select new { ToCompanyIdKey = g.Key, betweenDocs = g };
...
}
Sorry for bad English.
You can use the following code.
It simply uses the conditional operator to find out which is the ID of the other company. This information is than used to group the documents.