public void Edit(RoleViewModels model)
        {
            AspNetRole role = Repository.GetById(model.Id);

            role = Mapper.ModelToData(role, model);
            Repository.Save();
        }
Exemplo n.º 2
0
        public IActionResult Create(RoleViewModels roleModel)
        {
            RoleContext roleContext = new RoleContext(connectionString);

            roleModel.Region = roles();

            IActionResult retour = null;

            if (ModelState.IsValid)
            {
                Role role = new Role();

                role.Identifiant = roleModel.Identifiant;
                role.Nom         = roleModel.Nom;



                bool isOK = roleContext.Insert(role);
                retour = RedirectToAction("Index");
            }
            else
            {
                retour = View(roleModel);
            }

            return(retour);
        }
Exemplo n.º 3
0
        public RoleViewModels Get(int id)
        {
            var            roleEntity = dataBase.Roles.Get(id);
            RoleViewModels roleModel  = Mapper.Map <RoleViewModels>(roleEntity);

            return(roleModel);
        }
Exemplo n.º 4
0
        public override void Delete()
        {
            if (CurrentRoleViewModel == null)
            {
                return;
            }

            if (ModernDialog.ShowMessage("是否要删除当前角色?", "操作警告", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
            {
                return;
            }

            if (CurrentRoleViewModel.Id.Equals(Role.AdminRoleId))
            {
                ModernDialog.ShowMessage("系统默认管理员角色不能被删除。",
                                         "角色管理",
                                         MessageBoxButton.OK);
                return;
            }

            if (_roleDataAccessor.HasAssociatedUsers(CurrentRoleViewModel.Id))
            {
                ModernDialog.ShowMessage("当前角色已经分配到用户,无法被删除。",
                                         "角色管理",
                                         MessageBoxButton.OK);
                return;
            }

            // 停止同步数据库
            CurrentRoleViewModel.StopSyncToDatabase();
            // 删除角色视图模型
            RoleViewModels.Remove(CurrentRoleViewModel);
        }
Exemplo n.º 5
0
        public IActionResult Edit(RoleViewModels roleModel)
        {
            RoleContext roleContext = new RoleContext(connectionString);

            roleModel.Region = roles();
            //Rajouter des contrôles dynamiques

            //if(bugModel.IdentifiantSeverite == 2)
            //{
            //    ModelState.AddModelError("IdentifiantSeverite", "Ne peut être égal à 2");
            //}

            IActionResult retour = null;

            if (ModelState.IsValid)
            {
                Role role = new Role();

                role.Identifiant = (int)roleModel.Identifiant;
                role.Nom         = roleModel.Nom;


                bool isOK = roleContext.Update(role);
                retour = RedirectToAction("Index");
            }
            else
            {
                retour = View(roleModel);
            }

            return(retour);
        }
Exemplo n.º 6
0
        public IActionResult Create()
        {
            RoleViewModels model = new RoleViewModels();

            model.Region = roles();

            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            RoleViewModels roleViewModels = db.RoleViewModels.Find(id);

            db.RoleViewModels.Remove(roleViewModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
        public JsonResult GetbyID(int ID)
        {
            var            rol   = db.UserRoles.Where(x => x.RoleId == ID).SingleOrDefault();
            RoleViewModels model = new RoleViewModels();

            model = new RoleViewModels().ConvertFromRole(rol);
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 9
0
        public JsonResult Update(RoleViewModels model)
        {
            var rol = db.UserRoles.Where(x => x.RoleId == model.RoleId).SingleOrDefault();

            rol.RoleName = model.RoleName;
            rol.IsActive = model.IsActive;
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Create(RoleViewModels model)
        {
            var role = new ApplicationRole()
            {
                Name = model.name
            };
            await RoleManager.CreateAsync(role);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public ActionResult Edit(RoleViewModels model)
        {
            if (ModelState.IsValid)
            {
                Service.Edit(model);
                return(RedirectToAction("Index", "Role"));
            }

            return(View(model));
        }
Exemplo n.º 12
0
        public JsonResult Add(RoleViewModels model)
        {
            var rol = new UserRole();

            rol.RoleName = model.RoleName;
            rol.IsActive = model.IsActive;
            db.UserRoles.Add(rol);
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 13
0
 public ActionResult Edit([Bind(Include = "id,Name")] RoleViewModels roleViewModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(roleViewModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(roleViewModels));
 }
Exemplo n.º 14
0
        public async Task <ActionResult> Edit(RoleViewModels model)
        {
            var role = new ApplicationRole()
            {
                Id = model.Id, Name = model.Name
            };
            await RoleManager.UpdateAsync(role);

            return(RedirectToAction("Index"));
        }
        public void Add(RoleViewModels model)
        {
            AspNetRole role = new AspNetRole();

            role    = Mapper.ModelToData(role, model);
            role.Id = Guid.NewGuid().ToString();

            Repository.Add(role);
            Repository.Save();
        }
Exemplo n.º 16
0
        public ActionResult Edit(string id)
        {
            RoleViewModels model = Service.GetById(id);

            if (model == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            return(View(model));
        }
Exemplo n.º 17
0
        public ActionResult Create([Bind(Include = "id,Name")] RoleViewModels roleViewModels)
        {
            if (ModelState.IsValid)
            {
                db.RoleViewModels.Add(roleViewModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(roleViewModels));
        }
Exemplo n.º 18
0
        public ActionResult Index()
        {
            //Hämta info för Create/Read/Update Roles
            var model           = new RoleViewModels();
            var astridRolesList = _portalSosService.HamtaAllaAstridRoller();
            var filipRolesList  = _portalSosService.HamtaAllaFilipRoller();

            model.AstridRoller = astridRolesList.ToList();
            model.FilipRoller  = filipRolesList.ToList();
            ViewBag.Message    = "";
            return(View(model));
        }
Exemplo n.º 19
0
        public ActionResult Index()
        {
            var identityRoles = db.Roles.ToList();
            List <RoleViewModels> allRoles = new List <RoleViewModels>();

            foreach (var identityrole in identityRoles)
            {
                RoleViewModels role = new RoleViewModels();
                role.id   = identityrole.Id;
                role.Name = identityrole.Name;
                allRoles.Add(role);
            }
            return(View(allRoles));
        }
Exemplo n.º 20
0
        // GET: RoleViewModels/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RoleViewModels roleViewModels = db.RoleViewModels.Find(id);

            if (roleViewModels == null)
            {
                return(HttpNotFound());
            }
            return(View(roleViewModels));
        }
Exemplo n.º 21
0
        public IActionResult Edit(int id)
        {
            RoleContext    roleContext = new RoleContext(connectionString);
            Role           role        = roleContext.Get(id);
            RoleViewModels roleModel   = new RoleViewModels();

            roleModel.Identifiant = role.Identifiant;
            roleModel.Nom         = role.Nom;


            roleModel.Region = roles();

            return(View(roleModel));
        }
        public async Task <IActionResult> Create(RoleViewModels Role)
        {
            if (ModelState.IsValid)
            {
                var result = await _roleManager.CreateAsync(new IdentityRole(Role.Name));//Add new Role

                if (result.Succeeded)
                {
                    return(RedirectToAction(nameof(Index)));
                }

                AddErrors(result);
            }
            return(View(Role));
        }
Exemplo n.º 23
0
        public async Task <ActionResult> Edit(RoleViewModels model)
        {
            var current_data = await db.Role.Where(x => x.Id == model.Id).FirstOrDefaultAsync();

            var role = new ApplicationRole()
            {
                Id = model.Id, Name = model.Name
            };
            await RoleManager.UpdateAsync(role);

            current_data.Name            = model.Name;
            db.Entry(current_data).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 24
0
        public ActionResult Edit([Bind(Include = "id,Name")] RoleViewModels roleViewModels)
        {
            if (ModelState.IsValid)
            {
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));

                IdentityRole role = roleManager.FindById(roleViewModels.id);
                role.Name = roleViewModels.Name;
                roleManager.Update(role);

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(roleViewModels));
        }
Exemplo n.º 25
0
        public ActionResult DeleteConfirmed(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            IdentityRole role = getIdentityRole(id);

            var users       = UserManager.Users.Where(x => !x.UserName.Contains("@")).ToList();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
            var roleUsers   = roleManager.Roles.Single(x => x.Name.Equals(role.Name)).Users;

            users = (from r in roleUsers join u in users on r.UserId equals u.Id select u).Distinct().ToList();

            bool roleIsAssigned = false;
            int  roleCount      = users.Count;

            if (roleCount > 0)
            {
                roleIsAssigned = true;
            }

            //Assign the Identity Roles
            RoleViewModels roleViewModels = new RoleViewModels();

            roleViewModels.id   = role.Id;
            roleViewModels.Name = role.Name;

            if (roleViewModels == null)
            {
                return(HttpNotFound());
            }

            if (roleIsAssigned)
            {
                ModelState.AddModelError(roleViewModels.Name, "Cannot remove a Role that " + roleCount + " users are assigned to.");
                return(View(roleViewModels));
            }
            else
            {
                var roleToDelete = roleManager.FindByName(role.Name);
                roleManager.Delete(roleToDelete);

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 26
0
        public async Task <ActionResult> New(RoleViewModels model)
        {
            if (ModelState.IsValid)
            {
                IdentityResult result = await RoleManager.CreateAsync(new ApplicationRole(model.Name));

                if (result.Succeeded)
                {
                    TempData["message"] = $"The role: { model.Name } has successfully been added.";
                    return(RedirectToAction("index"));
                }
                else
                {
                    AddErrorsFromResult(result);
                }
            }
            return(View(model));
        }
Exemplo n.º 27
0
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Get the Identity Role
            IdentityRole role = getIdentityRole(id);

            //Assign the Identity Roles
            RoleViewModels roleViewModels = new RoleViewModels();

            roleViewModels.id   = role.Id;
            roleViewModels.Name = role.Name;

            if (roleViewModels == null)
            {
                return(HttpNotFound());
            }
            return(View(roleViewModels));
        }
Exemplo n.º 28
0
        public ActionResult Create([Bind(Include = "id,Name")] RoleViewModels roleViewModels)
        {
            if (ModelState.IsValid)
            {
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
                if (roleManager.RoleExists(roleViewModels.Name) == false)
                {
                    var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    role.Name = roleViewModels.Name;
                    roleManager.Create(role);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(roleViewModels.Name, "Role exists.");
                    return(View(roleViewModels));
                }
            }

            return(View(roleViewModels));
        }
Exemplo n.º 29
0
        /// <summary>
        /// 角色角色视图列表。
        /// </summary>
        private void ExecuteLoadRolesCommand()
        {
            // 使用AutoMapper实现实体间的映射
            Mapper.CreateMap <RoleViewModel, Role>();
            Mapper.CreateMap <Role, RoleViewModel>();

            // 获取所有Roles。
            var roles = _roleDataAccessor.GetAll();

            roles.ForEach(role =>
            {
                // 忽略系统管理员角色
                if (role.IsAdminRole())
                {
                    return;
                }
                // 为每一个Role创建一个RoleViewModel,用于界面绑定显示
                var roleViewModel = new RoleViewModel();

                Mapper.Map <Role, RoleViewModel>(role, roleViewModel);

                RoleViewModels.Add(roleViewModel);

                // 跟踪角色视图的属性变更,一旦发生变更则同步数据库
                roleViewModel.BeginSyncToDatabase();
            }
                          );

            if (RoleViewModels.Count > 0) // 默认选中第一个
            {
                CurrentRoleViewModel = RoleViewModels[0];
            }

            // 监听列表集合事件,并同步数据库
            RoleViewModels.CollectionChanged += RoleViewModelsCollectionChanged;

            UpdateTotals(RoleViewModels.Count);
        }
Exemplo n.º 30
0
        public async Task <ActionResult> Create(RoleViewModels model)
        {
            var role = new ApplicationRole()
            {
                Name = model.Name
            };
            await RoleManager.CreateAsync(role);

            LogsModels logs_add = new LogsModels
            {
                Id              = Guid.NewGuid(),
                Timestamp       = DateTime.UtcNow,
                TableName       = "AspNetRoles",
                RefId           = new Guid(role.Id),
                Action          = "Added",
                ColumnName      = "*ALL",
                UserAccounts_Id = User.Identity.GetUserId()
            };

            db.Logs.Add(logs_add);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }