Beispiel #1
0
        public async Task <ActionResult> EditProfile()
        {
            var user = await _user.GetByIdAsync(Session["adminId"]);

            var roles = await _role.GetAllAsync();

            ViewBag.RoleIds = new SelectList(roles, "RoleID", "RoleName");
            return(View(user));
        }
        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));
            }
        }
        public async Task <IActionResult> GetAllAsync()
        {
            var roles = await _roleServices.GetAllAsync();

            return(Ok(roles));
        }