我的项目的角色实体具有此建模的多个操作:{ public string Uid { get; set; } public string Descript { get; set; } public bool Premitive { get; set; } public virtual ICollection<ActionDto> Actions { get; set; } public string Name { get; set; } public bool IsDeleted { get; set; }}我使用 UnitOfWork Repository Pattern 的 create 方法是:public async Task<IHttpActionResult> Create([FromBody] RoleFullDto dto) { try { if (dto.Actions == null || dto.Actions.Count <= 0) return BadRequest(); //If I Pass Only action uid, return EntityModelException //When I Pass Complete Entity, Create New Action //foreach (var action in dto.Actions) //{ //var act = UnitOfWork.ActionRepository.Get(action.Uid); //action.ActionName = act.ActionName; //action.MenuId = act.MenuId; //action.PersianActionName = act.PersianActionName; //} var role = ModelFactory.GetRole(dto); if (role == null) return Content(HttpStatusCode.InternalServerError, dto); var result = await this.AppRoleManager.CreateAsync(role); if (!result.Succeeded) { return GetErrorResult(result); } return ActionResult<Role>(role, null, "CreateRole", HttpStatusCode.Created); } catch (Exception e) { Console.WriteLine(e); return InternalServerError(); } }我通过这个参数来创建新角色:{ Name: "TestRole1", Descript: "This is Test", Premitive: false, Actions: [{uid:1},{uid:2},{uid:3}]}但是此方法要添加 3 个存在于 Databese 中的新操作如何使用现有操作创建角色?
1 回答
- 1 回答
- 0 关注
- 147 浏览
添加回答
举报
0/150
提交
取消