本文整理汇总了C#中UnitOfWork.Get方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Get方法的具体用法?C# UnitOfWork.Get怎么用?C# UnitOfWork.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoAs
public static void DoAs(Agent a)
{
try
{
var uow = new UnitOfWork(a);
var b = uow.Get<Building>(1).SingleOrDefault();
if (b == null)
{
Console.WriteLine("Building not found");
Console.ReadLine();
return;
}
Console.WriteLine(b.Name);
Console.WriteLine(b.Floors.Count + " floors");
foreach (var item in b.Floors)
Console.WriteLine(" - " + item.Id);
}
catch (Exception ex)
{
Console.WriteLine("EX: " + ex.Message);
}
Console.ReadLine();
}
示例2: Main
static void Main(string[] args)
{
// Set up some dummy data. In this sample, we're storing people's role assignments as tuples of the role, plus the chain down the
// OU tree where it's assigned. This is so we can mimic the fact that a RA at parent counts as a RA at child easily in the dummy data
// In the real system, this would be implemented via real checks.
var uow = new UnitOfWork
{
Data = new Dictionary<int, object>
{
{1, new User {Id = 1, Name = "Arnold", Roles = new List<Tuple<string, string>> {Tuple.Create("ADM", "GLOBAL"), Tuple.Create("BOAD", "GLOBAL"), Tuple.Create("ICRA", "GLOBAL")}}},
{2, new User {Id = 2, Name = "Beth", Roles = new List<Tuple<string, string>> {Tuple.Create("BOAD", "GLOBAL"), Tuple.Create("ICRA", "GLOBAL")}}},
{9, new User {Id = 9, Name = "Cathy", Roles = new List<Tuple<string, string>> {Tuple.Create("ICRA", "GLOBAL")}}},
{3, new User {Id = 3, Name = "Donald", Roles = new List<Tuple<string, string>> {Tuple.Create("DA", "GLOBAL.SCHOOLS.STEIN"), Tuple.Create("FO", "GLOBAL.SCHOOLS.STEIN")}}},
{4, new User {Id = 4, Name = "Erwin", Roles = new List<Tuple<string, string>> {Tuple.Create("VW", "GLOBAL.OTSS"), Tuple.Create("FO", "GLOBAL.SCHOOLS.CIMS")}}},
{13, new User {Id = 13, Name = "Fernando", Roles = new List<Tuple<string, string>> {Tuple.Create("VW", "GLOBAL.OTSS")}}},
{14, new User {Id = 14, Name = "Gertrude", Roles = new List<Tuple<string, string>> {Tuple.Create("FO", "GLOBAL.SCHOOLS")}}},
{17, new User {Id = 17, Name = "Harold", Roles = new List<Tuple<string, string>> {Tuple.Create("FO", "GLOBAL.SCHOOLS.PLY.HELP")}}},
{5, new BudgetDetermination {Id = 5, Status = BudgetDeterminationStatusEnum.Initial}},
{6, new BudgetDetermination {Id = 6, Status = BudgetDeterminationStatusEnum.InProgress}},
{7, new BudgetDetermination {Id = 7, Status = BudgetDeterminationStatusEnum.Complete}},
{8, new BudgetDetermination {Id = 8, Status = BudgetDeterminationStatusEnum.Archived}},
{10, new SpaceAllocationAcknowledgement { Id = 10, Status = SpaceAllocationAcknowledgementStatusEnum.Initial, Department = "GLOBAL.SCHOOLS.STEIN"}},
{11, new SpaceAllocationAcknowledgement { Id = 11, Status = SpaceAllocationAcknowledgementStatusEnum.Acknowledged, Department = "GLOBAL.SCHOOLS.CIMS"}},
{12, new SpaceAllocationAcknowledgement { Id = 12, Status = SpaceAllocationAcknowledgementStatusEnum.Initial, Department = "GLOBAL.SCHOOLS.PLY"}},
{15, new SpaceAllocationAcknowledgement { Id = 15, Status = SpaceAllocationAcknowledgementStatusEnum.Initial, Department = "GLOBAL.OTSS"}},
{16, new SpaceAllocationAcknowledgement { Id = 16, Status = SpaceAllocationAcknowledgementStatusEnum.Initial, Department = "GLOBAL.SCHOOLS.PLY.HELP"}},
}
};
// Then print who can view each object
// The rules for BD's are: ADM's and BO's can both see BD's that are initial/in progress/completed, and only ADM's can see Archived BD's
var bdPerm = new BudgetDeterminationPermission.View();
// The rules for SAA's are: ADM's and BOAD's can see all SAA's, but an FO can only see an SA if it is an SAA for a department under where they're assigned the FO permission, and only if the SAA is initial or completed.
// You can see how this can get rather complicated, but if you peek inside the type, you'll see it's relatively simple to declare
var saaPerm = new SpaceAllocationAcknowledgementPermission.View();
for (int x = 5; x <= 8; x++)
{
var obj = uow.Get<BudgetDetermination>(x);
Console.WriteLine("Users that can see BD {0}: {1}", x, String.Join(", ", bdPerm.UsersWithPermission(obj, uow)));
}
for (int x = 10; x <= 16; x++)
{
var obj = uow.Get<SpaceAllocationAcknowledgement>(x);
Console.WriteLine("Users that can see SAA {0}: {1}", x, String.Join(", ", saaPerm.UsersWithPermission(obj, uow)));
if (x == 12) x = 15;
}
/*
OUTPUT:
Users that can see BD 5: Arnold, Beth
Users that can see BD 6: Arnold, Beth
Users that can see BD 7: Arnold, Beth
Users that can see BD 8: Arnold
Users that can see SAA 10: Donald, Gertrude, Arnold, Beth
Users that can see SAA 11: Erwin, Gertrude, Arnold, Beth
Users that can see SAA 12: Gertrude, Arnold, Beth
Users that can see SAA 16: Gertrude, Harold, Arnold, Beth
*/
Console.ReadKey();
}