public ActionResult AddOrEdit(int? id)
        {
            var model = new RoleViewModel();
            if (id.HasValue)
            {
                var dto = RoleService.Get(id.Value);
                model = Mapper.Map(dto, model);
            }

            return View(model);
        }
Beispiel #2
0
        public ActionResult AddOrEdit(int? id)
        {
            var model = new RoleViewModel();
            if (id.HasValue)
            {
                var item = Db.Get<Role>(id.Value);
                model = Mapper.Map(item, model);
            }

            return View(model);
        }
        public ActionResult AddOrEdit(RoleViewModel model)
        {
            if (model.Id > 0)
            {
                RoleService.Update(Mapper.Map<RoleDto>(model));
            }
            else
            {
                RoleService.Create(Mapper.Map<RoleDto>(model));
            }

            return RedirectToAction("List");
        }
Beispiel #4
0
        public ActionResult Index(int id)
        {
            var model = new RoleViewModel();

            var item = Db.Get<Role>(id);
            if (item == null)
            {
                return View("ServerError", (object)"Страница не найдена");
            }
            model = Mapper.Map(item, model);

            return View(model);
        }
Beispiel #5
0
        public ActionResult AddOrEdit(RoleViewModel model)
        {
            var item = new Role();
            if (model.Id > 0)
            {
                item = Db.Get<Role>(model.Id);
            }
            item = Mapper.Map(model, item);

            var result = Db.SaveOrUpdate(item);

            return RedirectToAction("List");
        }
Beispiel #6
0
        public ActionResult AddOrEdit(int? id)
        {
            var model = new RoleViewModel();
            if (id.HasValue)
            {
                var dto = RoleService.Get(id.Value);
                model = Mapper.Map(dto, model);
            }

            model.WebPermissions = MvcApplication.WebPermissions
                .Select(wp => wp.Name)
                .Distinct()
                .Select(x => new WebPermissionViewModel {  Name = x, Selected = model.WebPermissions.Any(wp => wp.Name == x)})
                .ToList();

            return View(model);
        }
Beispiel #7
0
        public ActionResult AddOrEdit(RoleViewModel model)
        {
            model.WebPermissions = model.WebPermissions.Where(wp => wp.Selected).ToList();
            foreach (var webPermission in model.WebPermissions)
            {
                webPermission.RoleId = model.Id;
            }

            if (model.Id > 0)
            {
                RoleService.Update(Mapper.Map<RoleDto>(model));
            }
            else
            {
                RoleService.Create(Mapper.Map<RoleDto>(model));
            }

            return RedirectToAction("List");
        }
        public ActionResult AddOrEdit(int? id)
        {
            var model = new UserViewModel();
            if (id.HasValue)
            {
                var item = Db.Get<User>(id.Value);
                model = Mapper.Map(item, model);
            }
            //добавим те роли, которых нет у пользователя, но есть в БД
            foreach (var role in Db.Select<Role>())
            {
                if (model.UserRoles.Any(ur => ur.Code == role.Code))
                    continue;
                var roleViewModel = new RoleViewModel();
                roleViewModel = Mapper.Map(role, roleViewModel);
                roleViewModel.Selected = false;
                model.UserRoles.Add(roleViewModel);
            }

            return View(model);
        }