Пример #1
0
        public async Task <IActionResult> AddRoleForUser([FromBody] UserRoleFormForDto model)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(model.UserId);

                if (user == null)
                {
                    return(NotFound("Kullanıcı bulunamadı"));
                }

                if (user.UserName == "ingame")
                {
                    return(BadRequest("Sistem kullanıcısı için değişiklik yapamazsınız"));
                }

                var roleExist = await _userManager.GetRolesAsync(user);

                if (roleExist.Contains(model.Role))
                {
                    return(BadRequest("Atamak istediğiniz rol zaten kullanıcıya verilmiş"));
                }

                await _userManager.AddToRoleAsync(user, model.Role);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Пример #2
0
        public async Task <IActionResult> UserRoleManagement(UserRoleFormForDto model)
        {
            var serRes = await _accountService.UserRoleManagement(GetToken());

            if (serRes.ResultStatus.Status != Enums.ResultStatus.Success)
            {
                AddSweetAlert("", serRes.ResultStatus.Explanation, Enums.NotificationType.warning);

                return(View(model));
            }

            model.Users = serRes.Result.Users;
            model.Roles = serRes.Result.Roles;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var addRoleSerRes = await _accountService.AddRoleForUser(GetToken(), model);

            if (addRoleSerRes.ResultStatus.Status != Enums.ResultStatus.Success)
            {
                AddSweetAlert("", addRoleSerRes.ResultStatus.Explanation, Enums.NotificationType.warning);
                return(View(model));
            }

            AddSweetAlert("", "Kullanıcıya başarıyla rol tanımlandı.", Enums.NotificationType.success);

            return(RedirectToAction("UserRoleManagement"));
        }
Пример #3
0
        public async Task <ServiceResult> AddRoleForUser(string token, UserRoleFormForDto model)
        {
            var serRes = new ServiceResult();

            var json       = JsonConvert.SerializeObject(model);
            var httpClinet = _httpClientFactory.CreateClient("ingamedemo");

            httpClinet.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            var response = await httpClinet.PostAsync("account/addroleforuser", new StringContent(json, Encoding.UTF8, "application/json"));

            if (!response.IsSuccessStatusCode)
            {
                var message = await response.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(message))
                {
                    message = "Beklenmedik bir hata meydana geldi. Lütfen daha sonra tekrar deneyiniz.";
                }

                serRes.ResultStatus.Explanation = message;
                return(serRes);
            }

            serRes.ResultStatus.Status = Enums.ResultStatus.Success;
            return(serRes);
        }
Пример #4
0
        public async Task <IActionResult> UserRoleManagement()
        {
            var model = new UserRoleFormForDto();

            var serRes = await _accountService.UserRoleManagement(GetToken());

            if (serRes.ResultStatus.Status != Enums.ResultStatus.Success)
            {
                AddSweetAlert("", serRes.ResultStatus.Explanation, Enums.NotificationType.warning);

                return(View(model));
            }

            model = serRes.Result;
            return(View(model));
        }
Пример #5
0
        public IActionResult UserRoleManagement()
        {
            try
            {
                var model = new UserRoleFormForDto
                {
                    Users = _mapper.Map <List <UserForDto> >(_userManager.Users.ToList()),
                    Roles = _mapper.Map <List <RoleForDto> >(_roleManager.Roles.ToList())
                };

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }