public OperationResponse <AppUserRoleInsertCommandOutputDTO> Execute(AppUserRoleInsertCommandInputDTO input)
 {
     using (var dbContextScope = this.DbContextScopeFactory.Create())
     {
         return(this.Repository.Insert(input));
     }
 }
        public OperationResponse <AppUserRoleInsertCommandOutputDTO> Insert(AppUserRoleInsertCommandInputDTO input)
        {
            var result = new OperationResponse <AppUserRoleInsertCommandOutputDTO>();

            try
            {
                var entity = new IdentityRole
                {
                    Id             = input.Id,
                    Name           = input.Name,
                    NormalizedName = input.NormalizedName,
                };

                var dbLocator = AmbientDbContextLocator.Get <IdentityDBContext>();
                {
                    dbLocator.Add(entity);
                    dbLocator.SaveChanges();

                    var dto = dbLocator.Set <IdentityRole>().Where(o => o.Id == entity.Id).Select(o => new AppUserRoleInsertCommandOutputDTO
                    {
                        Id             = o.Id,
                        Name           = o.Name,
                        NormalizedName = o.NormalizedName,
                    }).FirstOrDefault();

                    result.Bag = dto;
                }
            }
            catch (Exception ex)
            {
                result.AddException(null, ex);
            }

            return(result);
        }
        public async Task <IActionResult> Post([FromBody] AppUserRoleInsertCommandInputDTO model)
        {
            var result = new OperationResponse <AppUserRoleGetByIdCommandOutputDTO>();
            var entity = new IdentityRole
            {
                Name = model.Name
            };

            var createResult = await this.RoleManager.CreateAsync(entity);

            if (createResult.Succeeded)
            {
                var entityRole = await this.RoleManager.FindByNameAsync(model.Name);

                result.Bag = new AppUserRoleGetByIdCommandOutputDTO
                {
                    Id             = entityRole.Id,
                    Name           = entityRole.Name,
                    NormalizedName = entityRole.NormalizedName
                };
                //result.Bag = this.GetByIdCommand.Execute(createResult.Name);
            }
            else
            {
                createResult.Errors.ToList().ForEach(error => {
                    result.AddError($"{error.Code} {error.Description}");
                });
            }
            //var appResult = this.InsertCommand.Execute(model);
            return(result.IsSucceed ? (IActionResult)this.Ok(result) : (IActionResult)this.BadRequest(result));
        }