/// <summary>
 /// 转换为角色实体
 /// </summary>
 /// <param name="dto">角色数据传输对象</param>
 public static Role ToEntity(this RoleDto dto)
 {
     if (dto == null)
     {
         return(new Role());
     }
     return(dto.MapTo(new Role(dto.Id.ToGuid())));
 }
Example #2
0
 public virtual async Task CreateRole(RoleDto input)
 {
     //if (await _roleRepository.IsExistsRoleByName(input.CategoryName))
     //{
     //    throw new UserFriendlyException(L("NameIsExists"));
     //}
     var entity = await _roleManager.CreateAsync(input.MapTo <Role>());
 }
Example #3
0
        public virtual async Task UpdateRole(RoleDto input)
        {
            //if (await _roleRepository.IsExistsRoleByName(input.CategoryName, input.Id))
            //{
            //    throw new UserFriendlyException(L("NameIsExists"));
            //}
            var entity = await _roleManager.GetRoleByIdAsync(input.Id);

            await _roleManager.UpdateAsync(input.MapTo(entity));
        }
 /// <summary>
 /// 编辑role
 /// </summary>
 /// <param name="dto">实体</param>
 /// <returns></returns>
 public bool Update(RoleDto dto)
 {
     using (var scope = _dbScopeFactory.Create())
     {
         var db    = GetDb(scope);
         var dbSet = GetDbSet(db);
         //var entity = Mapper.Map<RoleDto, RoleEntity>(dto);
         var entity = dto.MapTo <RoleEntity>();
         dbSet.AddOrUpdate(entity);
         return(db.SaveChanges() > 0);
     }
 }
Example #5
0
 private bool SetRole(RoleDto dto)
 {
     CheckRole(dto);//检查用户输入
     if (dto.Id != Guid.Empty)
     {
         RoleDto dbDto = Dbc.Db.GetById <RoleDto>(dto.Id);
         ExHelper.ThrowIfNull(dbDto, "查找更新记录失败.");
         dbDto.MapTo(dto, a => a.Id);
     }
     Dbc.Db.Set(dto);
     return(true);
 }
Example #6
0
        public void Create(RoleDto role)
        {
            var entity = role.MapTo <RoleEntity>();

            entity.CreateTime = DateTime.Now;


            //var menuIdList = !string.IsNullOrEmpty(role.MenuIds) ? role.MenuIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List<string>();
            //menuIdList.ForEach(o =>
            //{
            //    var menu = _menuRopsitory.GetById(int.Parse(o));
            //    entity.Menus.Add(menu);
            //});
            _roleRopsitory.Insert(entity);
        }
Example #7
0
        public static VmRoleGrid ToGridVm(this RoleDto dto)
        {
            //return new VmRoleGrid
            //{
            //    Id = dto.Id,
            //    Name = dto.Name,
            //    IsAdmin = dto.IsAdmin,
            //    Enabled = dto.Enabled,
            //    DateCreated = dto.DateCreated.ToChineseDateTimeString(),
            //    Checked = dto.Checked
            //};
            VmRoleGrid vmRoleGrid = dto.MapTo <VmRoleGrid>();

            vmRoleGrid.CreationTime = dto.CreationTime.ToChineseDateTimeString();
            return(vmRoleGrid);
        }
Example #8
0
 public Result UpdateRole(RoleDto dto)
 {
     try
     {
         var model = dto.MapTo <RoleEntity>();
         var rlt   = UnitOfWorkService.Execute(() => _repo.Update(model));
         if (!rlt)
         {
             return(new Result(false, ""));
         }
         return(new Result(true, ""));
     }
     catch (Exception ex)
     {
         Logger.Error($"update role to exception:{ex}");
         return(new Result(false, "修改失败"));
     }
 }
Example #9
0
 public Result InsertRole(RoleDto dto)
 {
     try
     {
         var model = dto.MapTo <RoleEntity>();
         var id    = UnitOfWorkService.Execute(() => _repo.InsertAndGetId(model));
         if (!id.IsNullOrWhiteSpace())
         {
             return(new Result(false, ""));
         }
         return(new Result(true, ""));
     }
     catch (Exception ex)
     {
         Logger.Error($"add role to exception :{ex}");
         return(new Result(false, "添加失败"));
     }
 }
Example #10
0
        public override Task <RoleDto> CreateOrEditRole(RoleDto request, ServerCallContext context)
        {
            var role = request.MapTo <SysRole>();

            if (role.Id > 0)
            {
                var oldMenu = _role.SingleOrDefault(item => item.Id == role.Id);

                oldMenu.Name   = role.Name;
                oldMenu.Remark = role.Remark;
                role           = _role.Update(oldMenu);
            }
            else
            {
                role = _role.Insert(role);
            }

            return(Task.FromResult(role.MapTo <RoleDto>()));
        }
Example #11
0
        public void AddorUpdate(RoleDto dto)
        {
            var entity = dto.MapTo <Role>();
            //var query = _roleRepository.GetAllAsNoTracking();
            //var model = query.SingleOrDefault(p => p.Id == entity.Id);
            var model = _roleRepository.Find(entity.Id);

            if (model == null)
            {
                //AddBefore(entity);
                _roleRepository.Add(entity);
            }
            else
            {
                //UpdateBefore(entity);
                //model.Id = entity.Id;
                model.Name        = entity.Name;
                model.Description = entity.Description;
                model.IsAdmin     = entity.IsAdmin;
                model.Enabled     = entity.Enabled;
                model.Version     = entity.Version;
                _roleRepository.Update(model);
            }
        }
Example #12
0
 /// <summary>
 /// 添加新角色
 /// </summary>
 /// <param name="role">角色DTO对象</param>
 /// <returns>操作是否成功</returns>
 public int AddRole(RoleDto role)
 {
     return(baseAuthorityService.AddRole(role.MapTo <Role>()));
 }
Example #13
0
        public async Task <bool> EditAsync(RoleDto model)
        {
            var entity = model.MapTo <RoleInfo>();

            return(roleManage.EditTo(entity) ? await context.SaveChangesAsync() > 0 : false);
        }
Example #14
0
 public static RoleEntity ToEntity(this RoleDto model, RoleEntity destination)
 {
     return(model.MapTo(destination));
 }
Example #15
0
 public static RoleEntity ToEntity(this RoleDto model)
 {
     return(model.MapTo <RoleDto, RoleEntity>());
 }
Example #16
0
        public async Task <JsonResult> SaveRole([FromBody] RoleDto role)
        {
            await _roleAppService.Create(role.MapTo(new CreateRoleDto()));

            return(Json(new { reload = true }));
        }
Example #17
0
 public void AddorUpdate(RoleDto dto)
 {
     _roleDomainService.AddorUpdate(dto.MapTo <Role>());
 }
Example #18
0
 /// <summary>
 /// 更新角色
 /// </summary>
 /// <param name="role">角色DTO对象</param>
 /// <returns>操作是否成功</returns>
 public int UpdateRole(RoleDto role)
 {
     return(baseAuthorityService.UpdateRole(role.MapTo <Role>()));
 }