public IRole Represent(IRepresentationContext <long> representationContext) { if (representationContext == null) { representationContext = new RepresentationContext <long>(); } return(representationContext.GetOrAdd(Id, () => new RoleImpl(Name, Permisions))); }
public IUserReference Represent(IRepresentationContext <long> representationContext) { if (representationContext == null) { representationContext = new RepresentationContext <long>(); } var role = default(IRole); if (Role != null) { role = Role.Represent(representationContext); } return(representationContext.GetOrAdd(Id, () => new UserReferenceImpl(UserId, role))); }
public IStarredTread Represent(IRepresentationContext <long> representationContext) { if (representationContext == null) { representationContext = new RepresentationContext <long>(); } var userReference = default(IUserReference); if (UserReference != null) { userReference = UserReference.Represent(representationContext); } return(representationContext.GetOrAdd(Id, () => new StarredThreadImpl(ThreadKey, FromCode, ToCode, TimeToMailling, userReference))); }
public async Task <IReadOnlyList <IRole> > CreateDefaultsAsync(CancellationToken cancellationToken = default) { using (var context = await DatabaseStorageService.CreateContextAsync() .ConfigureAwait(continueOnCapturedContext: false)) { var defautls = new List <Role>() { new Role { Name = "Пользователь", Permisions = Permisions.ViewFavorites | Permisions.MangeFavorties, }, new Role { Name = "Администратор", Permisions = Permisions.ViewFavorites | Permisions.MangeFavorties | Permisions.ViewAnotherUsersFavories | Permisions.BlockUsers, }, }; var exists = await context .Set <Role>() .AsNoTracking() .Where(x => defautls.Select(r => r.Name).Contains(x.Name)) .ToListAsync(cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); if (exists.Count == 0) { context.Set <Role>().AddRange(defautls); await context.SaveChangesAsync(cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); var representationContext = new RepresentationContext <long>(); return(defautls.ConvertAll(x => x.Represent(representationContext))); } var repesentationContext = new RepresentationContext <long>(); return(exists.ConvertAll(x => x.Represent(repesentationContext))); } }