예제 #1
0
        public ActionResult Edit(RoleUpdateModel model) // checkbox lardan gelen model
        {
            IdentityResult result;

            if (ModelState.IsValid)
            {
                // bu foreach ile istediğimiz id leri bu role atamış oluyoruz
                foreach (var userId in model.IdsToAdd ?? new string[] { }) // model içerisinden gelen IdsToAdd null ise bu foreach in hata vermemesi için dizi olarak algılanması gerekiyor ve null ise boş bir string dizi olarak oluşmasını sağlıyoruz
                {
                    result = userManager.AddToRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }

                // bu foreach ile istediğimiz id leri bu role den silmiş oluyoruz
                foreach (var userId in model.IdsToDelete ?? new string[] { })
                {
                    result = userManager.RemoveFromRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }
                return(RedirectToAction("Index"));
            }

            return(View("Error", new string[] { "aranılan role yok" }));
        }
예제 #2
0
        public ActionResult Edit(RoleUpdateModel model)
        {
            IdentityResult result;

            if (ModelState.IsValid)
            {
                //ids to add null olursa foreachın hata vermemesi için bir dizi olarak algılaması gerekiyor
                foreach (var item in model.IdsToAdd ?? new string[] { })
                {
                    result = userManager1.AddToRole(item, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }
                foreach (var item in model.IdsToDelete ?? new string[] { })
                {
                    result = userManager1.RemoveFromRole(item, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }
                return(RedirectToAction("Index"));
            }


            return(View("Error", new string[] { "aranılan rol yok" }));
        }
예제 #3
0
        public IActionResult Delete(string id)
        {
            var model = new RoleUpdateModel();

            model.Delete(id);
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public Result Update(RoleUpdateModel model)
        {
            var result = new Result();

            try
            {
                var role = _roleRepository.GetById(model.Id);
                if (role == null)
                {
                    result.Success = false;
                    result.Message = "Role not found";
                    return(result);
                }

                role.Name        = model.Name;
                role.IsActive    = model.IsActive;
                role.UpdatedDate = DateTime.Now;



                //TODO: CryptoHelperdan parola cryptolanacak

                _roleRepository.Update(role);
                result.Success = true;
                result.Message = "Role was updated succesfully";
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = "It has a an error when creating role " + ex.Message;
            }

            return(result);
        }
        public ActionResult Edit(RoleUpdateModel model)
        {
            IdentityResult result; //for mistake or success

            if (ModelState.IsValid)
            {
                foreach (var userId in model.IdsToAdd ?? new string[] { }) //If there is no IdsToAdd, we did something like this to avoid getting error in foreach
                {
                    result = userManager.AddToRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }
                foreach (var userId in model.IdsToDelete ?? new string[] { })
                {
                    result = userManager.RemoveFromRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View("Error", new string[] { "Aranılan rol yok" }));
        }
        public ActionResult Edit(RoleUpdateModel model)
        {
            IdentityResult result;

            if (ModelState.IsValid)
            {
                foreach (var userId in model.IdsToAdd ?? new string[] { })
                {
                    result = userManager.AddToRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }
                foreach (var userId in model.IdsToDelete ?? new string[] { })
                {
                    result = userManager.RemoveFromRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View("Error", new string[] { "Role Bulunamadı" }));
        }
예제 #7
0
        public ActionResult edit(RoleUpdateModel model)
        {
            IdentityResult result;

            if (ModelState.IsValid)
            {
                foreach (var item in model.IdsToAdd ?? new string[] { })
                {
                    result = userManagar.AddToRole(item, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("error", result.Errors));
                    }
                }
                foreach (var user in model.IdsToDelete ?? new string[] { })
                {
                    result = userManagar.RemoveFromRole(user, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("error", result.Errors));
                    }
                }
                return(RedirectToAction("index"));
            }
            return(View("error", new string[] { "Something went wrong!" }));
        }
예제 #8
0
 public async Task <IActionResult> Add(RoleUpdateModel model)
 {
     if (ModelState.IsValid)
     {
         await model.AddNewRole();
     }
     return(View(model));
 }
예제 #9
0
        public IActionResult Update(string roleId)
        {
            var p     = RoleDal.Find(roleId);
            var model = new RoleUpdateModel()
            {
                RoleId = p.RoleId,
                Name   = p.Name.Trim(),
            };

            return(View(model));
        }
예제 #10
0
        public IActionResult UpdateRole(int id)
        {
            var role = _roleManager.Roles.FirstOrDefault(I => I.Id == id);
            //rol boş mu dolu kontrol edilmesi lazımdı.
            RoleUpdateModel model = new RoleUpdateModel
            {
                Id   = role.Id,
                Name = role.Name
            };

            return(View(model));
        }
예제 #11
0
        public async Task <IActionResult> Put(int id, [FromBody] RoleUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _Roleservice.UpdateAsync(id, model.name);

            string Data_Created = "Role updated successfully.";

            return(Ok(Json(Data_Created)));
        }
예제 #12
0
 public IActionResult Update(RoleUpdateModel model)
 {
     try
     {
         var p = RoleDal.Find(model.RoleId);
         p.Name = model.Name;
         RoleDal.Update(p);
         return(Json(1));
     }
     catch (Exception ex)
     {
         return(Json(ex.Message));
     }
 }
예제 #13
0
        public async Task <IResultModel> Update(RoleUpdateModel model)
        {
            var entity = await _roleRepository.FirstAsync(model.Id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            _mapper.Map(model, entity);

            var result = await _roleRepository.UpdateAsync(entity);

            return(ResultModel.Result(result));
        }
예제 #14
0
        public async Task <IResultModel> Update(RoleUpdateModel model)
        {
            if (await _repository.Exists(model.Name, model.Id))
            {
                return(ResultModel.HasExists);
            }

            var role = await _repository.GetAsync(model.Id);

            _mapper.Map(model, role);

            var result = await _repository.UpdateAsync(role);

            return(ResultModel.Result(result));
        }
예제 #15
0
        public async Task <IActionResult> Post([FromBody] RoleUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var entity = Mapper.Map <Role>(model);

            var result = await _Roleservice.CreateRoleAsync(entity);

            string Data_Created = "Role created successfully.";

            return(Ok(Json(Data_Created)));
        }
예제 #16
0
        public async Task<IResultModel> Update(RoleUpdateModel model)
        {
            if (await _repository.Exists(model.Name, model.Id))
                return ResultModel.HasExists;

            var role = await _repository.GetAsync(model.Id);
            if (role.IsSpecified)
                return ResultModel.Failed("指定角色不允许编辑");

            _mapper.Map(model, role);

            var result = await _repository.UpdateAsync(role);

            return ResultModel.Result(result);
        }
예제 #17
0
        public ActionResult Edit(RoleUpdateModel model)
        {
            if (ModelState.IsValid)
            {
                foreach (var userid in model.IdsToAdd ?? new string[] { })
                {
                    userManager.AddToRole(userid, model.RoleName);
                }
                foreach (var userid in model.IdsToDelete ?? new string[] { })
                {
                    userManager.RemoveFromRole(userid, model.RoleName);
                }
                return(RedirectToAction("Index"));
            }

            return(View("Error", new string[] { "Aranılan Rol Bulunamadı" }));
        }
예제 #18
0
        public ActionResult Edit(RoleUpdateModel model)
        {
            IdentityResult result;

            if (ModelState.IsValid)
            {
                foreach (var userId in model.IdsToAdd ?? new string[] { })
                {
                    var user = userManager.Users.FirstOrDefault(i => i.Id == userId);
                    result = userManager.AddToRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }



                    else if (result.Succeeded)
                    {
                        TempData["Success"] = user.Name + " " + user.LastName + " İsimli kullanıcının rolü güncellendi !";
                    }
                }


                foreach (var userId in model.IdsToDelete ?? new string[] { })
                {
                    var user = userManager.Users.FirstOrDefault(i => i.Id == userId);
                    result = userManager.RemoveFromRole(userId, model.RoleName);
                    if (!result.Succeeded)
                    {
                        return(View("Error", result.Errors));
                    }
                    else if (result.Succeeded)
                    {
                        TempData["Success"] = user.Name + " " + user.LastName + " İsimli kullanıcısının rolü güncellendi !";
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View("Error", new string[] { "Aranılan rol yok" }));
        }
        public async Task <Result <Unit> > Store(Guid storageKey, RoleUpdateModel updateModel)
        {
            var storageEvent = updateModel.ToStorage(storageKey);
            var entity       =
                await(_context.Events as IQueryable <RoleEventStorageModel>)
                .FirstOrDefaultAsync(x =>
                                     x.StorageKey == storageEvent.StorageKey && x.User == storageEvent.User);

            if (entity is null)
            {
                _context.Events.Add(storageEvent);
            }
            else
            {
                _context.Entry(entity).CurrentValues.SetValues(storageEvent);
            }

            await _context.SaveChangesAsync();

            return(new Unit());
        }
예제 #20
0
        public async Task <IActionResult> UpdateRole(RoleUpdateModel model)
        {
            var tobeUpdateRole = _roleManager.Roles.
                                 Where(I => I.Id == model.Id).FirstOrDefault();

            tobeUpdateRole.Name = model.Name;
            var identityResult = await _roleManager.UpdateAsync(tobeUpdateRole);

            if (identityResult.Succeeded)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                foreach (var error in identityResult.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
예제 #21
0
        public async Task <Result <Unit> > Store(ulong guildId, RoleUpdateModel updateModel)
        {
            var storage = new JailDataStorage(guildId.MapUlongToLong(), updateModel.User.MapUlongToLong(),
                                              updateModel.RolesChanged.ToStorage());
            var entity =
                await(_context.JailDatas as IQueryable <JailDataStorage>)
                .FirstOrDefaultAsync(x =>
                                     x.GuildId == storage.GuildId && x.UserId == storage.UserId);

            if (entity is null)
            {
                _context.JailDatas.Add(storage);
            }
            else
            {
                _context.Entry(entity).CurrentValues.SetValues(storage);
            }

            await _context.SaveChangesAsync();

            return(new Unit());
        }
예제 #22
0
 public Task <IResultModel> Update(RoleUpdateModel model)
 {
     return(_service.Update(model));
 }
예제 #23
0
 public ActionResult Edit(RoleUpdateModel model)
 {
     return(View());
 }
예제 #24
0
 public Result Put([FromBody] RoleUpdateModel userUpdateModel)
 {
     return(_roleService.Update(userUpdateModel));
 }
예제 #25
0
 public Task <IResultModel> Update(RoleUpdateModel model)
 {
     return(Task.FromResult(ResultModel.Success("修改")));
 }
예제 #26
0
        public async Task <IActionResult> UpdateRoleAsync([FromBody] RoleUpdateModel model)
        {
            var            result   = new Result();
            IdentityResult IdResult = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(new
                    {
                        Errors = new SerializableError(ModelState),
                        Success = false
                    }));
                }

                if (model.Claims != null)
                {
                    string[] invalidClaims = model.Claims.Where(c => _uow.Permissions.GetAllPermissions().Where(x => x.Value == c) == null).ToArray();
                    if (invalidClaims.Any())
                    {
                        result = new Result()
                        {
                            Success = false,
                            Errors  = new[] { "The following claim types are invalid: " + string.Join(", ", invalidClaims) },
                            Data    = null
                        };

                        return(BadRequest(result));
                    }
                }

                var role = _roleManager.Roles.FirstOrDefault(r => r.Id == model.Id);
                if (role == null)
                {
                    return(NotFound(result));
                }

                role.DisplayName = model.DisplayName ?? role.DisplayName;
                role.IsActive    = model.IsActive;
                IdResult         = await _roleManager.UpdateAsync(role);

                if (!IdResult.Succeeded)
                {
                    result = new Result()
                    {
                        Success = false,
                        Errors  = IdResult.Errors.Select(e => e.Description).ToArray()
                    };

                    return(BadRequest(result));
                }

                if (model.Claims != null)
                {
                    var roleClaims      = (await _roleManager.GetClaimsAsync(role)).Where(c => c.Type == CustomClaimTypes.Permission);
                    var roleClaimValues = roleClaims.Select(c => c.Value).ToArray();

                    var claimsToRemove = roleClaimValues.Except(model.Claims).ToArray();
                    var claimsToAdd    = model.Claims.Except(roleClaimValues).Distinct().ToArray();

                    if (claimsToRemove.Any())
                    {
                        foreach (string claim in claimsToRemove)
                        {
                            IdResult = await _roleManager.RemoveClaimAsync(role, roleClaims.Where(c => c.Value == claim).FirstOrDefault());

                            if (!IdResult.Succeeded)
                            {
                                result = new Result()
                                {
                                    Success = false,
                                    Errors  = IdResult.Errors.Select(e => e.Description).ToArray()
                                };

                                return(BadRequest(result));
                            }
                        }
                    }

                    if (claimsToAdd.Any())
                    {
                        foreach (string claim in claimsToAdd)
                        {
                            IdResult = await _roleManager.AddClaimAsync(role, new Claim(CustomClaimTypes.Permission, _uow.Permissions.GetPermissionByValue(claim)));

                            if (!IdResult.Succeeded)
                            {
                                result = new Result()
                                {
                                    Success = false,
                                    Errors  = IdResult.Errors.Select(e => e.Description).ToArray()
                                };

                                return(BadRequest(result));
                            }
                        }
                    }
                }

                result.Success = true;
                result.Data    = new
                {
                    Role = role,
                    model.Claims
                };

                return(Ok(result));
            }
            catch (Exception ex)
            {
                result.AddError(ex.Message);
                return(BadRequest(result));
            }
        }
예제 #27
0
        //[Authorize(Policy = "InternalOfficials")]
        public IActionResult Add()
        {
            var model = new RoleUpdateModel();

            return(View(model));
        }