예제 #1
0
        public ActionResult RoleEdit(int id)
        {
            var entity = this.roles.GetById(id);
            FimaRolesViewModel model = this.Mapper.Map <FimaRolesViewModel>(entity);

            model.Users = this.users.All()
                          .Where(x => !x.FimaRoles.Select(y => y.Name).ToList().Contains(model.Name))
                          .Select(x => x.UserName)
                          .ToList();

            return(this.View(model));
        }
예제 #2
0
        public ActionResult RoleEdit(string met, int id, FimaRolesViewModel model)
        {
            var entity = this.roles.GetById(id);

            if (met == null || model.FimaUsers.Count() <= 0)
            {
                FimaRolesViewModel m = this.Mapper.Map <FimaRolesViewModel>(entity);
                m.Users = this.users.All()
                          .Where(x => !x.FimaRoles.Select(y => y.Name).ToList().Contains(m.Name))
                          .Select(x => x.UserName)
                          .ToList();

                return(this.View(m));
            }

            if (met == "add")
            {
                foreach (var userName in model.FimaUsers)
                {
                    var user = this.users.All()
                               .Where(u => u.UserName == userName)
                               .FirstOrDefault();

                    if (user != null)
                    {
                        entity.FimaUsers.Add(user);
                    }
                }
            }
            else if (met == "remove")
            {
                foreach (var userName in model.FimaUsers)
                {
                    var user = this.users.All()
                               .Where(u => u.UserName == userName)
                               .FirstOrDefault();

                    if (user != null && entity.FimaUsers.Contains(user))
                    {
                        entity.FimaUsers.Remove(user);
                    }
                }
            }

            this.roles.Save();

            return(this.RedirectToAction("Roles"));
        }