Esempio n. 1
0
        public static void Init()
        {
            Mapper.AddMap <AdminPermission, AdminPermissionDto>(src =>
            {
                var adminUserViewModel = new AdminPermissionDto();
                adminUserViewModel.InjectFrom(src);

                if (src.ParentId > 0)
                {
                    adminUserViewModel.IsParentSelected = true;
                }

                return(adminUserViewModel);
            });

            Mapper.AddMap <AdminPermissionDto, AdminPermission>((from, to) =>
            {
                var existing = to as AdminPermission ?? new AdminPermission();
                existing.InjectFrom(new LoopInjection(new[] { "ParentId", "Left", "Right" }), from);

                if (from.IsParentSelected)
                {
                    existing.ParentId = from.ParentId;
                }

                return(existing);
            });
        }
Esempio n. 2
0
        public Result Edit(AdminPermissionDto dto)
        {
            var validator = new AdminPermissionValidator(_adminPermissionRepository);
            var result    = validator.ValidateResult(dto);

            if (!result.Success)
            {
                return(result);
            }

            var entity = _adminPermissionRepository.Find(dto.Id);

            if (entity == null)
            {
                return(new Result().SetBlankRedirect());
            }

            Mapper.Map <AdminPermission>(dto, entity);

            _adminPermissionRepository.Update(entity);

            _unitOfWork.Commit();

            _adminPermissionRepository.MoveToParentNode("AdminPermissions", dto.Id,
                                                        dto.IsParentSelected ? dto.ParentId : null);

            AdminRoleCacheManager.ClearCache();

            return(result.SetSuccess(Messages.RecordSaved));
        }
Esempio n. 3
0
        public JsonResult Create(AdminPermissionDto dto)
        {
            var result = _adminPermissionService.Create(dto);

            if (result.Success)
            {
                result.Redirect = Url.Action("Edit", new { id = result.Id });
            }

            return(ToJsonResult(result));
        }
Esempio n. 4
0
        public JsonResult Edit(AdminPermissionDto model)
        {
            var result = _adminPermissionService.Edit(model);

            if (result.IsRedirect)
            {
                result.Redirect = Url.Action("Index");
            }

            if (!result.Success)
            {
                return(ToJsonResult(result));
            }

            Flash.Success(result.Message);
            result.Redirect = Url.Action("Edit", "AdminPermissions", new { model.Id });

            return(ToJsonResult(result));
        }
Esempio n. 5
0
        public Result Create(AdminPermissionDto dto)
        {
            var validator = new AdminPermissionValidator(_adminPermissionRepository);
            var result    = validator.ValidateResult(dto);

            if (!result.Success)
            {
                return(result);
            }

            var entity = Mapper.Map <AdminPermission>(dto);

            _adminPermissionRepository.Insert(entity);

            _unitOfWork.Commit();
            AdminRoleCacheManager.ClearCache();

            result.Id = entity.Id;

            return(result.SetSuccess(Messages.RecordSaved));
        }