public virtual TEntity Get(TopLevelDomain id) { if (_repository.Contains(id)) { return(_repository.Get(id)); } throw new KeyNotFoundException($"{typeof(TEntity)} with id {id} was not found"); }
/// <summary> /// Gets the entity with the specified unique identifier. /// </summary> /// <param name="id">The unique identifier.</param> /// <returns>The entity.</returns> /// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown if an entity with the given id is not found.</exception> public virtual TEntity Get(TId id) { if (_repository.Contains(id)) { return(_repository.Get(id)); } throw new KeyNotFoundException(string.Format("{0} with id {1} was not found", typeof(TEntity), id)); }
public ActionResult Index() { var model = new StudyGroupsIndex() { TestResults = _readOnlyRepository.Get().ResultMatrix }; return(View(model)); }
private int getEffectiveRights(Subject subject, List <Entity> entities, long key, IReadOnlyRepository <EntityPermission> entityPermissionRepository, IReadOnlyRepository <PartyUser> partyUserRepository, IReadOnlyRepository <Party> partyRepository, IReadOnlyRepository <PartyRelationship> partyRelationshipRepository) { //var subject = subject.Id == null ? null : subjectRepository.Query(s => s.Id == subjectId).FirstOrDefault(); if (entities.Count == 0) { return(0); } var eids = entities.Select(e => e.Id); var rights = new List <int> { entityPermissionRepository.Get(m => m.Subject == null && eids.Contains(m.Entity.Id) && m.Key == key).FirstOrDefault()?.Rights ?? 0 }; if (subject is User) { var partyUser = partyUserRepository.Query(m => m.UserId == subject.Id).FirstOrDefault(); if (partyUser != null) { var userParty = partyRepository.Get(partyUser.PartyId); var entityNames = entities.Select(m => m.Name); var entityParty = partyRepository .Query(m => entityNames.Contains(m.PartyType.Title) && m.Name == key.ToString()) .FirstOrDefault(); if (userParty != null && entityParty != null) { var partyRelationships = partyRelationshipRepository.Query(m => m.SourceParty.Id == userParty.Id && m.TargetParty.Id == entityParty.Id); rights.AddRange(partyRelationships.Select(m => m.Permission)); } } var user = subject as User; var subjectIds = new List <long>() { user.Id }; subjectIds.AddRange(user.Groups.Select(g => g.Id).ToList()); rights.AddRange(entityPermissionRepository.Get(m => subjectIds.Contains(m.Subject.Id) && eids.Contains(m.Entity.Id) && m.Key == key).Select(e => e.Rights).ToList()); } if (subject is Group) { rights.Add(entityPermissionRepository.Get(m => m.Subject.Id == subject.Id && eids.Contains(m.Entity.Id) && m.Key == key).FirstOrDefault()?.Rights ?? 0); } return(rights.Aggregate(0, (left, right) => left | right)); }
public IQueryable <T> Get(Expression <Func <T, bool> > exp = null) { var items = _repository.Get().AsQueryable(); if (exp == null) { return(items); } return(items.Where(exp)); }
public IEnumerable <PostDto> Get() { var entities = _repository.Get(); if (entities == null) { throw new Exception($"Unable to retrieve blog posts."); } return(entities.Select(Map)); }
private int getRights(Subject subject, Entity entity, long key, IReadOnlyRepository <EntityPermission> entityPermissionRepository) { if (subject == null) { return(entityPermissionRepository.Get(m => m.Subject == null && m.Entity.Id == entity.Id && m.Key == key).FirstOrDefault()?.Rights ?? 0); } if (entity == null) { return(0); } return(entityPermissionRepository.Get(m => m.Subject.Id == subject.Id && m.Entity.Id == entity.Id && m.Key == key).FirstOrDefault()?.Rights ?? 0); }
// GET: api/Article public IEnumerable <DTO.Product> Get() { IReadOnlyCollection <Product> products = _repository.Get(); List <DTO.Product> dtos = new List <DTO.Product>(); foreach (var product in products) { var dto = _assembler.ToDto(product); dtos.Add(dto); } return(dtos); }
public void HandleRequest(IRequest request) { var characters = new List <Character>(); var characterIds = request.Data.GetOrDefault(k.characterID, new int[0]); foreach (var characterId in characterIds) { var character = Character.Get(characterId); if (character != Character.None) { characters.Add(character); } } var characterEids = request.Data.GetOrDefault(k.characterEID, new long[0]); foreach (var characterEid in characterEids) { var character = Character.GetByEid(characterEid); if (character != Character.None) { characters.Add(character); } } var result = characters.Select(c => _characterProfileRepository.Get(c.Id)).Where(p => p != null).ToDictionary("c", p => p.ToDictionary()); Message.Builder.FromRequest(request).WithData(result).WrapToResult().WithEmpty().Send(); }
public void OpeningMultipleSessionsShouldKeepOnlyOneActiveSession(int numberOfSessions) { IHubContext <SessionHub> hubContext = null; ISessionRepository sessionRepository = null; IReadOnlyRepository <string, HubConnectionContext> connectionRepository = null; Thread[] threads = null; SessionHubMethods <SessionHub> hubMethods = null; ConcurrentQueue <Exception> exceptions = null; "Given Axle SignalR hub" .x(() => { exceptions = new ConcurrentQueue <Exception>(); threads = new Thread[numberOfSessions]; hubContext = A.Fake <IHubContext <SessionHub> >(); sessionRepository = new InMemorySessionRepository(); connectionRepository = A.Fake <IReadOnlyRepository <string, HubConnectionContext> >(); A.CallTo(() => connectionRepository.Get(A <string> .Ignored)).Returns(A.Fake <HubConnectionContext>()); hubMethods = new SessionHubMethods <SessionHub>(hubContext, sessionRepository, connectionRepository); }); "When I open multiple sessions with the same user ID" .x(() => { for (int i = 0; i < numberOfSessions; i++) { threads[i] = new Thread(() => SafeExecute(() => this.StartSession(hubMethods), exceptions)); } for (int i = 0; i < numberOfSessions; i++) { threads[i].Start(); } }); "Then only one session of that user remains" .x(() => { Thread.Sleep(500); exceptions.Should().BeEmpty(); var activeSessionsOfUser = sessionRepository.GetByUser(UserId); activeSessionsOfUser.Count().Should().Be(1); }) .Teardown(() => { foreach (var thread in threads) { if (thread.IsAlive) { thread.Join(); } } }); }
public IList <UserAppModel> GetUsers(SearchRule[] search_rules, OrderingRule[] ordering_rules) { IReadOnlyRepository <DtoUser> readOnlyRepository = repositoryFactory.CreateReadOnlyUsersRepository(); IEnumerable <DtoUser> users = readOnlyRepository.Get(search_rules, ordering_rules); AbstractMapper <DtoUser, UserAppModel> mapper = mapperFactory.Create <DtoUser, UserAppModel>(); return(mapper.Map(users)); }
public UserAppModel GetUser(int id) { IReadOnlyRepository <DtoUser> readOnlyRepository = repositoryFactory.CreateReadOnlyUsersRepository(); DtoUser user = readOnlyRepository.Get(id); AbstractMapper <DtoUser, UserAppModel> mapper = mapperFactory.Create <DtoUser, UserAppModel>(); return(mapper.Map(user)); }
public void ReloadAll() { dbContext.Stocks.RemoveRange(dbContext.Stocks); var data = stockRepository.Get(); dbContext.Stocks.AddRange(data); var rowsChanged = dbContext.SaveChanges(); }
public static void Import(IRepository destination,IReadOnlyRepository sourceRepository) { var getKeys = sourceRepository as IGetKeys; if(getKeys != null) { foreach(var key in getKeys.GetKeys()) { destination.Set(key, sourceRepository.Get(key)); } } }
public override void Get(BusinessObject sender, BusinessConsultEventArgs args) { IReadOnlyRepository <DtoUser> repository = repositoryFactory.CreateReadOnlyUsersRepository(); DtoUser dtoUser = repository.Get(args.entityId); User user = new User(dtoUser.ID, dtoUser.UserName, dtoUser.Hash, dtoUser.Active, sender.GetBusinessEvents()); args.result = new List <User>() { user }; }
public async Task AddRecords(IDictionary <string, string> texts, string fromCode, string toCode, Guid createdById) { var keys = texts.Select(x => x.Key.ToLower()).ToList(); var records = await _readOnlyRepository.Get <TranslateItem>(filter : x => keys.Contains(x.Id)); foreach (var textInit in texts) { var text = textInit.Key.ToLower(); var old = records.FirstOrDefault(x => x.Id == text); var item = new TranslateItem() { Id = text, TextRu = textInit.Value, Translated = text != textInit.Value.ToLower() }; if (old == null) { _writeOnlyRepository.Add(item, createdById); } } _writeOnlyRepository.Commit(); }
public async Task HandleAsync(CartCreatedEvent @event) { var customer = await _customerRepository.Get(@event.CustomerId.IdAsString()); var cartReadModel = new CartReadModel { Id = @event.AggregateId.IdAsString(), CustomerId = customer.Id, CustomerName = customer.Name, TotalItems = 0 }; await _cartRepository.Insert(cartReadModel); }
public async Task HandleAsync(ProductAddedEvent @event) { var product = await _productRepository.Get(@event.ProductId.IdAsString()); var cart = await _cartRepository.Get(@event.AggregateId.IdAsString()); var cartItem = CartItemReadModel.CreateFor(@event.AggregateId.IdAsString(), @event.ProductId.IdAsString()); cartItem.ProductName = product.Name; cartItem.Quantity = @event.Quantity; cart.TotalItems += @event.Quantity; await _cartRepository.Update(cart); await _cartItemRepository.Insert(cartItem); }
private List <MetadataPackageUsage> GetPackages(Int64 structureId) { using (IUnitOfWork uow = this.GetUnitOfWork()) { IReadOnlyRepository <MDS.MetadataStructure> repo = uow.GetReadOnlyRepository <MDS.MetadataStructure>(); List <MetadataPackageUsage> list = new List <MetadataPackageUsage>(); MDS.MetadataStructure metadataStructure = repo.Get(structureId); if (metadataStructure.Parent != null) { list.AddRange(GetPackages(metadataStructure.Parent.Id)); } list.AddRange(metadataStructure.MetadataPackageUsages); return(list); } }
public override void Init() { var page = m_repository.Get <ContentPage>(View.CurrentItemId); if (page == null) { return; } View.Headline = page.Headline; View.Summary = page.Summary; View.Content = page.Content; if (page.Widgets != null) { View.Widgets = page.Widgets; } }
/// <summary> /// make a hash from isUniqe custom attributes and check it with all of the other parties hash /// </summary> /// <param name="partyType"></param> /// <param name="partyCustomAttrVals"></param> /// <returns></returns> public bool CheckUniqueness(IReadOnlyRepository <PartyX> repo, PartyType partyType, string hash, PartyX currentParty = null) { if (!string.IsNullOrEmpty(hash)) { var parties = repo.Get(item => item.PartyType.Id == partyType.Id); if (currentParty != null && currentParty.Id != 0) { parties = parties.Where(item => item.Id != currentParty.Id).ToList(); } foreach (var party in parties) { if (hash == GetHash(party.CustomAttributeValues.ToList())) { return(false); } } } return(true); }
public List <MetadataPackageUsage> GetEffectivePackages(Int64 structureId) { using (IUnitOfWork uow = this.GetUnitOfWork()) { IReadOnlyRepository <MDS.MetadataPackageUsage> repo = uow.GetReadOnlyRepository <MDS.MetadataPackageUsage>(); /*PostgreSQL82Dialect, DB2Dialect*/ if (AppConfiguration.DatabaseDialect.Equals("DB2Dialect")) { return(GetPackages(structureId)); } else //if (AppConfiguration.DatabaseDialect.Equals("PostgreSQL82Dialect")) { Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("metadataStructureId", structureId); List <MetadataPackageUsage> usages = repo.Get("GetEffectivePackageUsages", parameters).ToList(); return(usages); // structure.MetadataPackageUsages.ToList(); // plus all the packages of the parents } } }
public override void GetBy(BusinessObject sender, BusinessConsultEventArgs args) { List <SearchRule> searchRules = new List <SearchRule>(); foreach (string condition in args.conditions) { searchRules.Add(new SearchRule { condition = condition }); } IReadOnlyRepository <DtoUser> repository = repositoryFactory.CreateReadOnlyUsersRepository(); List <User> list = new List <User>(); var getResult = repository.Get(searchRules.ToArray(), new OrderingRule[0]); foreach (DtoUser dto in getResult) { list.Add(new User(dto.ID, dto.UserName, dto.Hash, dto.Active, sender.GetBusinessEvents())); } args.result = list; }
/// <summary> /// Gets the specified entity identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Store.</returns> /// <exception cref="NotValidException"></exception> /// <exception cref="Core.Common.Exceptions.NotValidException"></exception> /// <exception cref="ResourceNotFoundException"></exception> /// <exception cref="Core.Common.Exceptions.ResourceNotFoundException"></exception> protected T Get(TId id) { if (id == null) { CreateErrors.NotValid("", nameof(id)); } if (string.IsNullOrEmpty(id.ToString()) || id.ToString() == Guid.Empty.ToString() || id.ToString() == "0") { throw new NotValidException(id.ToString()); } T entity = ReadOnlyRepository.Get(id); if (entity == null) { CreateErrors.NotFound(id); } return(entity); }
/// <summary> /// make a hash from isUniqe custom attributes and check it with all of the other parties hash /// </summary> /// <param name="partyType"></param> /// <param name="partyCustomAttrVals"></param> /// <returns></returns> public bool CheckUniqueness(IReadOnlyRepository <PartyX> repo, List <PartyCustomAttributeValue> partyCustomAttrVals, PartyX currentParty = null) { Contract.Requires(partyCustomAttrVals.Any(), "Provided list must have one entity at least."); var partyTypeId = partyCustomAttrVals.First().CustomAttribute.PartyType.Id; string hash = GetHash(partyCustomAttrVals); if (!string.IsNullOrEmpty(hash)) { var parties = repo.Get(item => item.PartyType.Id == partyTypeId); if (currentParty != null && currentParty.Id != 0) { parties = parties.Where(item => item.Id != currentParty.Id).ToList(); } foreach (var party in parties) { if (hash == GetHash(party.CustomAttributeValues.ToList())) { return(false); } } } return(true); }
/// <summary> /// Indicates whether an entity which matches the given predicate exists. /// </summary> /// <param name="predicate">The predicate to filter the entity.</param> /// <returns>true, if an entity exists for given predicate; otherwise, false.</returns> public static bool Any <T>(this IReadOnlyRepository <T> repository, Func <T, bool> predicate) { return(repository.Get().Any(predicate)); }
{ /// <summary> /// Finds entities with the given <paramref name="predicate"/>. /// </summary> /// <param name="predicate">The search predicate.</param> /// <returns>A collection of entities matching the search predicate.</returns> public static IEnumerable <T> FindBy <T>(this IReadOnlyRepository <T> repository, Expression <Func <T, bool> > predicate) { var query = repository.Get().Where(predicate).AsEnumerable(); return(query); }
public IActionResult Services() { return(Ok(_serviceReadOnlyRepository.Get())); }
public IActionResult Vehicles() { return(Ok(_VehicleReadOnlyRepository.Get())); }
public virtual TEntity Get(int id, bool @readonly = false) { return(@readonly ? _readOnlyRepository.Get(id) : _repository.Get(id)); }
public IActionResult Owners() { return(Ok(_ownerReadOnlyRepository.Get())); }