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); } }
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)); } }
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)); }
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); }
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)); }
public TasksController( ITaskService taskService, IMapper mapper ) { _taskService = taskService; _mapper = mapper; _principal = new ContextPrincipal(HttpContext.User); }
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))); }
public OrganizationsController( IOrganizationService organizationService, IUserService userService, IMapper mapper ) { _organizationService = organizationService; _userService = userService; _mapper = mapper; _principal = new ContextPrincipal(HttpContext.User); }
public AssetsController( IAssetService assetService, IFileService fileService, IMapper mapper ) { _assetService = assetService; _fileService = fileService; _mapper = mapper; _principal = new ContextPrincipal(HttpContext.User); }
public FoldersController( IFolderService folderService, IAssetService assetService, IMapper mapper ) { _folderService = folderService; _assetService = assetService; _mapper = mapper; _principal = new ContextPrincipal(HttpContext.User); }
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)); }
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)); }
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); }
public FilesController( ITaskService taskService, IFileService fileService, IMapper mapper, IClusterClient orleansClient ) { _taskService = taskService; _fileService = fileService; _mapper = mapper; _orleansClient = orleansClient; _principal = new ContextPrincipal(); }
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)); }
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); }
public virtual async Task <bool> ObjectExistsAsync(ContextPrincipal principal, Guid resourceId) { return(await _repo.ExistsAsync(obj => obj.Id == resourceId)); }
public virtual async Task <TBizModel> GetAsBiz(ContextPrincipal principal, Guid resourceId) { TEntity dbObject = await this.Get(principal, resourceId); return(_mapper.Map <TBizModel>(dbObject)); }
public virtual async Task <Guid> Create(ContextPrincipal principal, TEntity obj) { await _repo.InsertAndSaveAsync(obj); return(await Task.FromResult(obj.Id)); }
public virtual async Task <TEntity> Get(ContextPrincipal principal, Guid resourceId) { return(await _repo.FindByIDAsync(resourceId)); }
public IActionResult TokenInfo() { ContextPrincipal principal = new ContextPrincipal(HttpContext.User); return(Ok(principal.Claims.ToDictionary(cl => cl.Type, cl => cl.Value))); }
public virtual async Task <bool> Update(ContextPrincipal principal, TEntity obj, Guid resourceId) { obj.Id = resourceId; return(await _repo.UpdateAndSaveAsync(obj) > 0); }
public UsersController(IUserService userService, IMapper mapper) { _userService = userService; _mapper = mapper; _principal = new ContextPrincipal(HttpContext.User); }