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)); }
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(); } }
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); }
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)); }
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(); }
public async Task Add(TEntity entity, CancellationToken cancellationToken) { await Context.AddAsync(entity, cancellationToken); }
public async Task <TEntity> Add(TEntity entity) { var result = await _dataBaseContext.AddAsync(entity); return(result.Entity); }
public virtual async Task AddAllAsync(IEnumerable <T> Items) => await context.AddAsync(Items);