本文整理汇总了C#中Role.TranslateToEntity方法的典型用法代码示例。如果您正苦于以下问题:C# Role.TranslateToEntity方法的具体用法?C# Role.TranslateToEntity怎么用?C# Role.TranslateToEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role.TranslateToEntity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
public Role Post(Role request)
{
RoleEntity entity = request.TranslateToEntity();
if (entity.Id == 0)
entity.Id = GenericRepository.GetMaxIdIncrement<RoleEntity>(AuthAdminDatabase, RolesCollection);
entity.RootParentId = entity.RootParentId == 0 ? entity.Id : entity.RootParentId;
entity.ParentId = entity.ParentId == 0 ? entity.Id : entity.ParentId;
entity = GenericRepository.Add(AuthAdminDatabase, RolesCollection, entity);
// add to parent child objects
if (entity.Id != entity.ParentId)
{
RoleEntity parentEntity = GenericRepository.GetItemTopById<RoleEntity>(AuthAdminDatabase, RolesCollection,
entity.ParentId);
if (parentEntity != null)
{
parentEntity.ChildRoleIds.Add(entity.Id);
parentEntity = GenericRepository.Add(AuthAdminDatabase, RolesCollection, parentEntity);
}
}
return entity.TranslateToResponse();
}
示例2: Put
public Role Put(Role request)
{
RoleEntity currentEntity = GenericRepository.GetItemTopById<RoleEntity>(AuthAdminDatabase, RolesCollection, request.Id);
RoleEntity entity = request.TranslateToEntity();
entity = GenericRepository.Add(AuthAdminDatabase, RolesCollection, entity);
// If parentid different from entity remove from current parent entity and add to new parent entity
if (currentEntity.ParentId != entity.ParentId)
{
//remove from current parent
RoleEntity currentParentEntity = GenericRepository.GetItemTopById<RoleEntity>(AuthAdminDatabase, RolesCollection, currentEntity.ParentId);
if (currentParentEntity != null)
{
currentParentEntity.ChildRoleIds.Remove(entity.Id);
currentParentEntity = GenericRepository.Add(AuthAdminDatabase, RolesCollection, currentParentEntity);
}
//add to new parent
RoleEntity parentEntity = GenericRepository.GetItemTopById<RoleEntity>(AuthAdminDatabase, RolesCollection, entity.ParentId);
if (parentEntity != null)
{
parentEntity.ChildRoleIds.Add(entity.Id);
parentEntity = GenericRepository.Add(AuthAdminDatabase, RolesCollection, parentEntity);
}
}
return entity.TranslateToResponse();
}