示例#1
0
        public virtual async Task <bool> Purge(ContextPrincipal principal, Guid resourceId)
        {
            TEntity obj = null;

            try {
                obj = await _repo.FindByIDAsync(resourceId);
            }
            catch (Exception e) {
                Logger.Error(
                    string.Format(@"An exception has been thrown searching for resource {0}!", resourceId), e);
                return(false);
            }

            if (obj == null)
            {
                throw new ApplicationException(@"Object not found.");
            }

            try {
                return(await _repo.DeleteAndSaveAsync(obj) > 0);
            }
            catch (Exception e) {
                Logger.Error(@"Commit failed for unit-of-work!", e);
                return(false);
            }
        }
示例#2
0
        public async Task <IActionResult> RevokeRefreshToken(string refreshToken)
        {
            if (string.IsNullOrWhiteSpace(refreshToken))
            {
                return(BadRequest(OAuthBadRequest));
            }

            try {
                ContextPrincipal principal = new ContextPrincipal(HttpContext.User);

                RefreshToken token = await unitOfWork.TokenRepository.FindOneAsync(
                    t => t.UserId.Equals(principal.UserId) && t.RefreshTokenValue.Equals(refreshToken), o => o.OrderBy(u => u.Id), null
                    );

                if (null != token)
                {
                    unitOfWork.TokenRepository.Delete(token);
                    await unitOfWork.Save();

                    return(Ok());
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception) {
                return(BadRequest(OAuthBadRequest));
            }
        }
示例#3
0
        public async Task <IEnumerable <Guid> > GetDirectChildrenAsGuids(ContextPrincipal principal, Guid parentId, int start, int limit)
        {
            List <Guid> result = new List <Guid>();

            int parentRank = (await _unitOfWork.EntityAncestorRepository.FindProjectionAsync(
                                  anc => anc.EntityId == parentId && anc.AncestorId.Value == parentId,
                                  pr => pr.Rank,
                                  o => o.OrderBy(u => u.AncestorId),
                                  0,
                                  1)).FirstOrDefault();

            IEnumerable <EntityAncestor> children = await _unitOfWork.EntityAncestorRepository.FindWithInclude <EntityAncestor>(
                ancLeft => ancLeft.AncestorId.Value == parentId, // all who have the parent in their path...
                ancLeft => ancLeft.EntityId,
                ancRight => ancRight.AncestorId.Value,
                ancRight => ancRight.EntityId == ancRight.AncestorId && ancRight.Rank == parentRank + 1,
                null,
                start,
                limit); // ...and their rank is parentRank + 1

            if (!children.Any())
            {
                return(result);
            }

            return(children.Select(x => x.EntityId));
        }
示例#4
0
        public override async Task <Guid> Create(ContextPrincipal principal, Organization organization)
        {
            organization.Id         = Guid.NewGuid();
            organization.CreatedBy  = principal.UserId;
            organization.ModifiedBy = principal.UserId;

            await base.InsertAncestors(organization, Entity.RootId);

            VFileSystemItem folder = new VFileSystemItem {
                Id           = Guid.NewGuid(),
                Title        = organization.Title,
                CreatedBy    = principal.UserId,
                ModifiedBy   = principal.UserId,
                DateCreated  = DateTime.UtcNow,
                DateModified = DateTime.UtcNow,
                Deleted      = false,
                Type         = EVItemType.Folder
            };

            await base.InsertAncestors(folder, organization.Id);

            _unitOfWork.EntityResourceRepository.Insert(organization);
            organizationUnitOfWork.VFileSystemItemRepository.Insert(folder);

            int persistedObjects = await _unitOfWork.Save();

            if (persistedObjects <= 0)
            {
                throw new InvalidOperationException(@"No DB records have been persisted!");
            }

            return(organization.Id);
        }
示例#5
0
 public virtual async Task <IEnumerable <TEntity> > Find(
     ContextPrincipal principal,
     Expression <Func <TEntity, bool> > expression,
     int start,
     int limit)
 {
     return(await _repo.FindAsync(p => true, null, start, limit));
 }
示例#6
0
 public TasksController(
     ITaskService taskService,
     IMapper mapper
     )
 {
     _taskService = taskService;
     _mapper      = mapper;
     _principal   = new ContextPrincipal(HttpContext.User);
 }
示例#7
0
        public virtual async Task <Tuple <int, int> > Delete(
            ContextPrincipal principal, Expression <Func <TEntity, bool> > expression)
        {
            IEnumerable <TEntity> matching = await _repo.FindAsync(expression);

            int matchingCount = matching.Count();

            return(await _repo.DeleteRangeAndSaveAsync(matching).ContinueWith((deleted) => new Tuple <int, int>(matchingCount, deleted.Result)));
        }
示例#8
0
 public OrganizationsController(
     IOrganizationService organizationService,
     IUserService userService,
     IMapper mapper
     )
 {
     _organizationService = organizationService;
     _userService         = userService;
     _mapper    = mapper;
     _principal = new ContextPrincipal(HttpContext.User);
 }
示例#9
0
 public AssetsController(
     IAssetService assetService,
     IFileService fileService,
     IMapper mapper
     )
 {
     _assetService = assetService;
     _fileService  = fileService;
     _mapper       = mapper;
     _principal    = new ContextPrincipal(HttpContext.User);
 }
示例#10
0
 public FoldersController(
     IFolderService folderService,
     IAssetService assetService,
     IMapper mapper
     )
 {
     _folderService = folderService;
     _assetService  = assetService;
     _mapper        = mapper;
     _principal     = new ContextPrincipal(HttpContext.User);
 }
示例#11
0
        public override async Task <bool> Update(ContextPrincipal principal, TEntity entity, Guid resourceId)
        {
            if (null == principal || null == entity)
            {
                throw new ArgumentNullException();
            }

            entity.ModifiedBy   = principal.UserId;
            entity.DateModified = DateTime.UtcNow;

            return(await base.Update(principal, entity, resourceId));
        }
示例#12
0
        public virtual async Task <bool> SoftDelete(ContextPrincipal principal, Guid resourceId)
        {
            TEntity entityToUpdate = await base.Get(principal, resourceId);

            if (null == entityToUpdate)
            {
                throw new ApplicationException(@"Could not find entity to soft delete it!");
            }

            entityToUpdate.Deleted = true;
            return(await Update(principal, entityToUpdate, resourceId));
        }
示例#13
0
        public virtual async Task <IEnumerable <TBizModel> > FindAsBiz(
            ContextPrincipal principal,
            Expression <Func <TEntity, bool> > expression,
            int start,
            int limit)
        {
            IEnumerable <TEntity> dbObjects = await this.Find(principal, org => true, start, limit);

            IEnumerable <TBizModel> bizModels = _mapper.Map <IEnumerable <TEntity>, IEnumerable <TBizModel> >(dbObjects);

            return(bizModels);
        }
示例#14
0
 public FilesController(
     ITaskService taskService,
     IFileService fileService,
     IMapper mapper,
     IClusterClient orleansClient
     )
 {
     _taskService   = taskService;
     _fileService   = fileService;
     _mapper        = mapper;
     _orleansClient = orleansClient;
     _principal     = new ContextPrincipal();
 }
示例#15
0
        public override async Task <IEnumerable <TEntity> > Find(
            ContextPrincipal principal,
            Expression <Func <TEntity, bool> > expression,
            int start,
            int limit)
        {
            if (null == principal || null == expression)
            {
                throw new ArgumentNullException();
            }

            expression = expression.And(ent => !ent.Deleted);

            return(await base.Find(principal, expression, start, limit));
        }
示例#16
0
        public virtual async Task <Guid> Create(ContextPrincipal principal, TEntity entity, Guid parentId)
        {
            if (null == principal || null == entity || Guid.Empty == parentId)
            {
                throw new ArgumentException();
            }

            entity.Id         = Guid.NewGuid();
            entity.CreatedBy  = principal.UserId;
            entity.ModifiedBy = principal.UserId;

            await InsertAncestors(entity, parentId);

            _unitOfWork.EntityResourceRepository.Insert(entity);

            int persistedObjects = await _unitOfWork.Save();

            if (persistedObjects <= 0)
            {
                throw new InvalidOperationException(@"No DB records have been persisted!");
            }

            return(entity.Id);
        }
示例#17
0
 public virtual async Task <bool> ObjectExistsAsync(ContextPrincipal principal, Guid resourceId)
 {
     return(await _repo.ExistsAsync(obj => obj.Id == resourceId));
 }
示例#18
0
        public virtual async Task <TBizModel> GetAsBiz(ContextPrincipal principal, Guid resourceId)
        {
            TEntity dbObject = await this.Get(principal, resourceId);

            return(_mapper.Map <TBizModel>(dbObject));
        }
示例#19
0
        public virtual async Task <Guid> Create(ContextPrincipal principal, TEntity obj)
        {
            await _repo.InsertAndSaveAsync(obj);

            return(await Task.FromResult(obj.Id));
        }
示例#20
0
 public virtual async Task <TEntity> Get(ContextPrincipal principal, Guid resourceId)
 {
     return(await _repo.FindByIDAsync(resourceId));
 }
示例#21
0
        public IActionResult TokenInfo()
        {
            ContextPrincipal principal = new ContextPrincipal(HttpContext.User);

            return(Ok(principal.Claims.ToDictionary(cl => cl.Type, cl => cl.Value)));
        }
示例#22
0
 public virtual async Task <bool> Update(ContextPrincipal principal, TEntity obj, Guid resourceId)
 {
     obj.Id = resourceId;
     return(await _repo.UpdateAndSaveAsync(obj) > 0);
 }
示例#23
0
 public UsersController(IUserService userService, IMapper mapper)
 {
     _userService = userService;
     _mapper      = mapper;
     _principal   = new ContextPrincipal(HttpContext.User);
 }