public async Task <string> SetRight( string userId, string resourceId, RightType type, Permission permission) { var userRight = await Get(userId, resourceId, type); if (userRight.IsNotNull()) { return(userRight.Id); } var id = _idGenerator.New(); userRight = new UserRight { Id = id, UserId = userId, ResourceId = resourceId, Rights = permission, Type = type }; Log.TraceFormat( "Add right: user {0} to [{1:G},{2}] => rights {3:X} ({3:G})", userId, type, resourceId, permission); await _dbContext.SaveAsync(userRight); return(id); }
public Task Add(T item) { UpdateTableTracker(); Task task = _context.SaveAsync(item); return(task); }
private async Task <string> Create(TagCreateData data) { var tags = await _context.Where <Tag>(nameof(Tag.Name), data.Name); var tag = tags.FirstOrDefault(); // only create a new tag, if it doesn't already exist if (tag != null && !tag.Id.IsNullOrWhitespace()) { return(tag.Id); } var create = new Tag { Id = _idGenerator.New(), Name = data.Name, CreatedBy = _userId, CreatedAt = DateTime.UtcNow }; await _context.SaveAsync(create); Log.DebugFormat("New tag {0} created by user {1}", create.Id, _userId); return(create.Id); }
/// <summary> /// Creates a book, adds it to the DynamoDB ProductCatalog table, retrieves /// the new book from the table, updates the dimensions and writes the /// changed item back to the table. /// </summary> /// <param name="context">The DynamoDB context object used to write and /// read data from the table.</param> public static async Task AddRetrieveUpdateBook(IDynamoDBContext context) { // Create a book. DimensionType myBookDimensions = new DimensionType() { Length = 8M, Height = 11M, Thickness = 0.5M, }; Book myBook = new Book { Id = 501, Title = "AWS SDK for .NET Object Persistence Model Handling Arbitrary Data", Isbn = "999-9999999999", BookAuthors = new List <string> { "Author 1", "Author 2" }, Dimensions = myBookDimensions, }; // Add the book to the DynamoDB table ProductCatalog. await context.SaveAsync(myBook); // Retrieve the book. Book bookRetrieved = await context.LoadAsync <Book>(501); // Update the book dimensions property. bookRetrieved.Dimensions.Height += 1; bookRetrieved.Dimensions.Length += 1; bookRetrieved.Dimensions.Thickness += 0.2M; // Write the changed item to the table. await context.SaveAsync(bookRetrieved); }
public async Task <Expense> InsertExpense(Expense exp) { exp.Id = System.Guid.NewGuid().ToString(); await context.SaveAsync(exp, default(System.Threading.CancellationToken)); return(exp); }
public async Task Create(Book book) { RepositoryBook dalBook = ConvertToRepositoryBook(book); //Save an book object await _dbContext.SaveAsync <RepositoryBook>(dalBook); }
private async Task <string> Create(TodoCreateData data) { var todo = new Todo { // lists have the Id == Parent // items have separate Id and Parent ids Id = _idGenerator.New(), Parent = data.Parent .ThrowConfigurationErrorsExceptionIfNullOrWhiteSpace("Parent cannot be empty"), Type = data.Type, Name = data.Name, State = data.State, Due = data.Due, CreatedBy = _creatorId, CreatedAt = DateTime.UtcNow, // TODO: validation/cross checking of tag references Tags = data.Tags }; await _context.SaveAsync(todo); Log.DebugFormat("New todo {0} for user {1} by user {1}", todo.Id, _creatorId); return(todo.Id); }
/// <inheritdoc/> public async Task SaveEntityAsync(IEntity entity) { entity.Updated = DateTime.UtcNow; switch (entity) { case TelegramChatInfo telegramChat: if (telegramChat.MinThresholdRate <= 0 || telegramChat.MaxThresholdRate <= 0) { var lastRate = await GetLastRateAsync(); if (lastRate != null) { telegramChat.UpdateThresholdRates(lastRate.Sell); } } await _dynamoDBContext.SaveAsync(telegramChat); break; case TinkoffExchangeRate rate: await _dynamoDBContext.SaveAsync(rate); break; } }
public static async void AddRetrieveUpdateBook(IDynamoDBContext context) { // Create a book. DimensionType myBookDimensions = new DimensionType() { Length = 8M, Height = 11M, Thickness = 0.5M }; Book myBook = new Book { Id = 501, Title = "AWS SDK for .NET Object Persistence Model Handling Arbitrary Data", Isbn = "999-9999999999", BookAuthors = new List <string> { "Author 1", "Author 2" }, Dimensions = myBookDimensions }; await context.SaveAsync(myBook); // Retrieve the book. Book bookRetrieved = await context.LoadAsync <Book>(501); // 3. Update property (book dimensions). bookRetrieved.Dimensions.Height += 1; bookRetrieved.Dimensions.Length += 1; bookRetrieved.Dimensions.Thickness += 0.2M; // Update the book. await context.SaveAsync(bookRetrieved); }
public async Task <string> Create(TenantCreateData data) { data.Code.ThrowInvalidDataExceptionIfNullOrWhiteSpace("Code cannot be empty"); if (await GetByCode(data.Code) is Tenant t) { Log.Debug($"Already exists tenant: '{t.Code}'"); return(t.Id); } var now = DateTime.UtcNow; var tenant = new Tenant { Id = _idGenerator.New(), Name = data.Name, Code = data.Code, Description = data.Description, CreatedBy = _creator.Id, CreatedAt = now, UpdatedAt = now }; await _context.SaveAsync(tenant); Log.TraceFormat("New tenant {0} '{1}' created by user {1}", tenant.Id, tenant.Code, _creator.Id); return(tenant.Id); }
public async Task <string> Create(T obj) { obj.Id = Guid.NewGuid().ToString(); await _context.SaveAsync(obj); return(obj.Id); }
public async Task CreateGame(string gameId) { var game = new GameDTO { GameId = gameId }; await _context.SaveAsync(game); }
public async Task <Location> AddLocation(string pk, Location location) { var table = DaBeerStorageTable.MapFromLocation(location, pk); await _context.SaveAsync(table); return(location); }
public async Task <ContactDetails> CreateContact(ContactDetailsEntity contactDetails) { _logger.LogDebug($"Calling IDynamoDBContext.SaveAsync for targetId {contactDetails.TargetId} and id {contactDetails.Id}"); contactDetails.LastModified = DateTime.UtcNow; await _dynamoDbContext.SaveAsync(contactDetails).ConfigureAwait(false); return(contactDetails.ToDomain()); }
public async Task <Person> PostNewPersonAsync(CreatePersonRequestObject requestObject) { _logger.LogDebug($"Calling IDynamoDBContext.SaveAsync"); var personDbEntity = requestObject.ToDatabase(); personDbEntity.LastModified = DateTime.UtcNow; await _dynamoDbContext.SaveAsync(personDbEntity).ConfigureAwait(false); return(personDbEntity.ToDomain()); }
public async Task <JsonResult> Create([FromBody] CreateThingCommand createItemCommand, CancellationToken cancellationToken) { var thing = new Thing { Id = Guid.NewGuid().ToString(), Name = createItemCommand.Name }; await _dynamoDbContext.SaveAsync <Thing>(thing, cancellationToken); return(new JsonResult(thing)); }
public async Task Store(string longUrl, string shortUrlKey, DateTime expireOn) { int epochSeconds = AWSSDKUtils.ConvertToUnixEpochSeconds(expireOn); var record = new FromShortUrl { LongUrl = longUrl, ShortUrlKey = shortUrlKey, ExpireOn = epochSeconds.ToString() }; await context.SaveAsync(record); }
public async Task GivenMaxContactDetailsAlreadyExist(Guid targetId) { Contacts.Clear(); Contacts.AddRange(CreateContactsForType(ContactType.email, targetId, MAX_EMAIL_CONTACTS)); Contacts.AddRange(CreateContactsForType(ContactType.phone, targetId, MAX_PHONE_CONTACTS)); foreach (var contact in Contacts) { await _dbContext.SaveAsync(contact).ConfigureAwait(false); } }
public async Task CreateAsync(TCode code, CancellationToken cancellationToken) { if (code == null) { throw new ArgumentNullException(nameof(code)); } cancellationToken.ThrowIfCancellationRequested(); await _context.SaveAsync(code); }
public void Set(string key, byte[] value, DistributedCacheEntryOptions options) { var cacheItem = Activator.CreateInstance <T>(); cacheItem.CacheId = key; cacheItem.Value = _encoding.GetString(value); cacheItem.CacheOptions = _cacheTtlManager.ToCacheOptions(options); cacheItem.Ttl = _cacheTtlManager.ToTtl(cacheItem.CacheOptions); _dynamoDbContext.SaveAsync(cacheItem).GetAwaiter().GetResult(); }
public async Task <string> Add(AdvertModel model) { var dbModel = _mapper.Map <AdvertDbModel>(model); dbModel.Id = Guid.NewGuid().ToString(); dbModel.CreationDateTime = DateTime.UtcNow; dbModel.AdvertStatus = AdvertStatus.Pending; await _dynamoDBContext.SaveAsync(dbModel); return(dbModel.Id); }
public async Task <bool> CreateAsync(City city) { try { await dynamoContext.SaveAsync(city); return(true); } catch (Exception) { return(false); } }
public async Task <IdentityResult> CreateAsync(TRole role, CancellationToken cancellationToken) { if (role == null) { throw new ArgumentNullException(nameof(role)); } cancellationToken.ThrowIfCancellationRequested(); await _context.SaveAsync(role, cancellationToken); return(IdentityResult.Success); }
public async Task <TAuthorization> CreateAsync(TAuthorization authorization, CancellationToken cancellationToken) { if (authorization == null) { throw new ArgumentNullException(nameof(authorization)); } cancellationToken.ThrowIfCancellationRequested(); await _context.SaveAsync(authorization); return(authorization); }
public async Task <Cart> GetOrCreateCartForUser(string userId) { var carts = await context.ScanAsync <Cart>(new List <ScanCondition> { new ScanCondition("UserId", ScanOperator.Equal, new string[] { userId }), new ScanCondition("CartStatus", ScanOperator.Equal, new string[] { "OPENED" }) }).GetRemainingAsync(); if (carts.Count == 0) { var cart = new Cart { Id = Guid.NewGuid().ToString(), CartItems = new List <CartItem>(), CartStatus = "OPENED", UserId = userId }; await context.SaveAsync(cart); return(cart); } else { return(carts[0]); } }
public Application CreateNewApplication(CreateApplicationRequest request) { var entity = new ApplicationDbEntity { Id = Guid.NewGuid(), CreatedAt = DateTime.UtcNow, Status = request.Status, MainApplicant = request.MainApplicant, OtherMembers = request.OtherMembers.ToList() }; _dynamoDbContext.SaveAsync(entity).GetAwaiter().GetResult(); return(entity.ToDomain()); }
public static async Task PerformCRUDOperations(IDynamoDBContext context) { int bookId = 1001; // Some unique value. Book myBook = new Book { Id = bookId, Title = "object persistence-AWS SDK for.NET SDK-Book 1001", Isbn = "111-1111111001", BookAuthors = new List <string> { "Author 1", "Author 2" }, }; // Save the book to the ProductCatalog table. await context.SaveAsync(myBook); // Retrieve the book from the ProductCatalog table. Book bookRetrieved = await context.LoadAsync <Book>(bookId); // Update some properties. bookRetrieved.Isbn = "222-2222221001"; // Update existing authors list with the following values. bookRetrieved.BookAuthors = new List <string> { " Author 1", "Author x" }; await context.SaveAsync(bookRetrieved); // Retrieve the updated book. This time, add the optional // ConsistentRead parameter using DynamoDBContextConfig object. await context.LoadAsync <Book>(bookId, new DynamoDBContextConfig { ConsistentRead = true, }); // Delete the book. await context.DeleteAsync <Book>(bookId); // Try to retrieve deleted book. It should return null. Book deletedBook = await context.LoadAsync <Book>(bookId, new DynamoDBContextConfig { ConsistentRead = true, }); if (deletedBook == null) { Console.WriteLine("Book is deleted"); } }
public async Task <Note> PostNewNoteAsync(CreateNoteRequest request) { var dbNote = new NoteDb { Id = Guid.NewGuid(), Description = request.Description, CreatedAt = request.CreatedAt.Value, TargetId = request.TargetId.Value, TargetType = request.TargetType.Value, Author = new AuthorDetails { Email = request.Author?.Email, FullName = request.Author?.FullName }, Categorisation = new Categorisation { Description = request.Categorisation?.Description, Category = request.Categorisation?.Category, SubCategory = request.Categorisation?.SubCategory } }; _logger.LogDebug($"Saving a new note for targetId: {dbNote.TargetId}, targetType: {Enum.GetName(typeof(TargetType), dbNote.TargetType)}"); await _dynamoDbContext.SaveAsync(dbNote).ConfigureAwait(false); return(dbNote.ToDomain()); }
public async Task <int> AddPerson(Person person) { var personDynamoDb = new PersonDynamoDb(person); await _context.SaveAsync(personDynamoDb); return(personDynamoDb.PersonId); }
public async Task <Guid> AddAUserAsync() { var userToAdd = new User { CreatedDateTime = DateTime.Now, Name = $"User{rando.Next(1000)}", UserId = Guid.NewGuid(), Roles = new List <Role> { new Role() { RoleName = $"TestRole{rando.Next(1000)}" }, new Role() { RoleName = $"TestRole{rando.Next(1000)}" }, new Role() { RoleName = $"TestRole{rando.Next(1000)}" } } }; await context.SaveAsync(userToAdd); return(userToAdd.UserId); }