コード例 #1
0
        public async Task <bool> Save(string name)
        {
            var role   = _roleFactory.CreateRole(name);
            var result = await _roleManager.CreateAsync(role);

            foreach (var error in result.Errors)
            {
                await _bus.RaiseEvent(new DomainNotification(result.ToString(), error.Description));
            }

            return(result.Succeeded);
        }
コード例 #2
0
        public IHttpActionResult Post(RoleWriteModel model)
        {
            if (string.IsNullOrWhiteSpace(model.CodeName))
            {
                return(BadRequest("No codename provided."));
            }

            if (string.IsNullOrWhiteSpace(model.DisplayName))
            {
                return(BadRequest("No display name provided."));
            }

            var role = _roleFactory.CreateRole(model.CodeName, model.DisplayName);

            _roleMapper.Map(model, role);

            _roleRepository.Save(role);

            var result = Mapper.Map <RoleReadModel>(role);

            return(CreatedAtRoute("GetRole", new { roleId = role.Id }, result));
        }