예제 #1
0
        public async Task Save(TEntity entity, CancellationToken cancellationToken)
        {
            var entry = _dbContext.Entry(entity);

            if (entry.State == EntityState.Detached)
            {
                await _dbContext.AddAsync(entity, cancellationToken);
            }
            await _dbContext.SaveChangesAsync(cancellationToken);
        }
        public async Task <OneObjectResponse <UserPropertyTypeView> > PostAsync(
            [FromBody] UserPropertyTypeCreateRequest request)
        {
            if (await dbContext.UserPropertyTypes.AnyAsync(upt => upt.Name == request.Name))
            {
                throw ResponseStatusCode.FieldExist.ToApiException();
            }
            var newType = mapper.Map <UserPropertyType>(request);
            await dbContext.AddAsync(newType);

            await dbContext.SaveChangesAsync();

            return(mapper.Map <UserPropertyTypeView>(newType));
        }
예제 #3
0
        private async Task CreateUserPropertyTypes()
        {
            foreach (var typeName in Enum.GetValues(typeof(UserPropertyNames)).Cast <UserPropertyNames>())
            {
                if (await dbContext.UserPropertyTypes.AnyAsync(t => t.Name == typeName.ToString()))
                {
                    continue;
                }
                await dbContext.AddAsync(new UserPropertyType {
                    Name          = typeName.ToString(),
                    DefaultStatus = UserPropertyStatus.NotConfirmed
                });

                await dbContext.SaveChangesAsync();
            }
        }
예제 #4
0
        public async Task <Message> AddMessage(Chat chat, MessageViewModel model)
        {
            Message message = new Message
            {
                Text         = model.Message,
                CreationTime = DateTime.Now,
                ChatId       = chat.Id,
                Direction    = chat.User1Id == model.CurrentUserId
            };

            await _dataBaseContext.AddAsync(message);

            await _dataBaseContext.SaveChangesAsync();

            return(message);
        }
예제 #5
0
        public async Task <IQueryable <UserProperty> > PutUserProperty(UserPropertyEditRequest request, Guid userId)
        {
            var targetType = await dbContext
                             .UserPropertyTypes
                             .SingleOrDefaultAsync(upt => upt.Id == request.Id)
                             ?? throw ResponseStatusCode.NotFound.ToApiException();

            var newProperty = mapper.Map <UserProperty>(request);

            newProperty.Status = targetType.DefaultStatus;
            newProperty.UserId = userId;
            await dbContext.AddAsync(newProperty);

            await dbContext.SaveChangesAsync();

            return(dbContext
                   .UserProperties
                   .Where(up => up.Id == newProperty.Id));
        }
예제 #6
0
        public async Task Process(RequestMetric metrics)
        {
            IServiceScope   scope            = _serviceProvider.CreateScope();
            DataBaseContext _dataBaseContext = scope.ServiceProvider.GetRequiredService <DataBaseContext>();
            await _dataBaseContext.AddAsync(metrics);

            await _dataBaseContext.SaveChangesAsync();

            foreach (MiddlewareMetric m in metrics.MiddlewareMetrics)
            {
                m.RequestMetricId = metrics.Id;
                m.Id = null;
            }
            await _dataBaseContext.AddRangeAsync(metrics.MiddlewareMetrics);

            await _dataBaseContext.SaveChangesAsync();

            scope.Dispose();
        }
예제 #7
0
 public async Task Add(TEntity entity, CancellationToken cancellationToken)
 {
     await Context.AddAsync(entity, cancellationToken);
 }
예제 #8
0
        public async Task <TEntity> Add(TEntity entity)
        {
            var result = await _dataBaseContext.AddAsync(entity);

            return(result.Entity);
        }
예제 #9
0
 public virtual async Task AddAllAsync(IEnumerable <T> Items) => await context.AddAsync(Items);