コード例 #1
0
        public Result Create(AdminRoleDto dto)
        {
            var validator = new AdminRoleValidator();
            var result    = validator.ValidateResult(dto);

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

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

            entity.SystemName = _adminRoleRepository.GenerateUniqueSlug(entity.Name, slugFieldName: "SystemName");

            _adminRoleRepository.Insert(entity);

            foreach (var permissionId in dto.Permissions)
            {
                entity.Permissionses.Add(_adminPermissionRepository.Find(permissionId));
            }

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

            result.Id = entity.Id;

            return(result.SetSuccess("Record has been successfully saved."));
        }
コード例 #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));
        }
コード例 #3
0
        public Result Edit(AdminRoleDto dto)
        {
            var validator = new AdminRoleValidator();
            var result    = validator.ValidateResult(dto);

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

            var entity = _adminRoleRepository.AsNoTracking
                         .Include(i => i.Permissionses)
                         .FirstOrDefault(s => s.Id == dto.Id);

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

            Mapper.Map <AdminRole>(dto, entity);
            entity.SystemName = _adminRoleRepository.GenerateUniqueSlug(entity.Name, slugFieldName: "SystemName", id: dto.Id);

            _adminRoleRepository.Update(entity);

            ChildRoleUpdate(entity, dto);

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

            return(result.SetSuccess("Record has been successfully saved."));
        }
コード例 #4
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));
        }