public async Task <ApiResponse> CreateRole([FromBody] RoleDto dto)
        {
            try
            {
                var getAllRole = await _roleServices.GetAllAsync();

                foreach (var roleName in getAllRole)
                {
                    if (dto.Name == roleName.Name)
                    {
                        return(new ApiResponse("identity entity framework core", dto, 400));
                    }
                }
                // save
                var role = _mapper.Map <Role>(dto);
                await _roleServices.AddAsync(role);

                return(new ApiResponse("Add role success", 200));
            }
            catch (Exception ex)
            {
                // return error message if there was an exception
                return(new ApiResponse("Can't add role", ex, 400));
            }
        }
Esempio n. 2
0
        public async Task <IResult> Add(RoleDto model)
        {
            var repositoryResult = await _roleServices.AddAsync(model);

            var result = ResponseHandler.GetResult(repositoryResult);

            return(result);
        }
 public ApiResponse CreateRole([FromBody] RoleDto dto)
 {
     try
     {
         // save
         var role = _mapper.Map <Role>(dto);
         _roleServices.AddAsync(role);
         return(new ApiResponse("Add role success", 200));
     }
     catch (Exception ex)
     {
         // return error message if there was an exception
         return(new ApiResponse("Can't add role", ex, 400));
     }
 }