public async Task <IActionResult> CreateStorage([FromBody] StorageRequestModel model) { if (ModelState.IsValid) { try { model.Storage.User = User.Identity.Name; model.Storage.IV = encryptor.GenerateIV(); var result = storageContext.Storages .Where(s => s.Name == model.Storage.Name && s.User == User.Identity.Name); if (model.Storage.Name == null) { return(new BadRequestObjectResult("Отсутствует имя хранилища")); } if (result.Count() != 0) { return(new BadRequestObjectResult("Хранилище с таким именем существует")); } if (!encryptor.CheckSizeKey(model.Key)) { return(new BadRequestObjectResult("Размер ключа [16, 24, 32]")); } await storageContext.Storages.AddAsync(model.Storage); HttpContext.Session.SetString("StorageIV", encryptor.ToString(model.Storage.IV)); HttpContext.Session.SetString("StorageKey", model.Key); await storageContext.Words.AddAsync( new WordModel() { User = User.Identity.Name, Storage = model.Storage.Name, ControlWord = encryptor.Encrypt(encryptor.ToByte("ControlWord")) }); await storageContext.SaveChangesAsync(); //LoadStorages(storageDB, model.Storage.Name); //storageDB.Connection.Close(); dataLite.Initializing(model.Storage.Name); dataLite.Close(); logger.LogInformation("Хранилище создано"); return(new OkObjectResult("Хранилище создано")); } catch (Exception ex) { logger.LogInformation("##### " + ex.StackTrace); return(new BadRequestObjectResult(ex.Message)); } } return(new BadRequestObjectResult("Модель данных не корректна")); }
public async Task <T> AddAsync(T entity) { await _dbContext.Set <T>().AddAsync(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task DeleteStorage(int idParam) { using var ctx = new StorageDbContext(); var articleToDelete = await ctx.Storages.FindAsync(idParam); ctx.Storages.Remove(articleToDelete); await ctx.SaveChangesAsync(); }
public async Task UpdateStorage(int idParam, string nameParam) { using var ctx = new StorageDbContext(); var articleToUpdate = await ctx.Storages.FindAsync(idParam); articleToUpdate.Name = nameParam; ctx.Storages.Update(articleToUpdate); await ctx.SaveChangesAsync(); }
/// <inheritdoc /> public async Task <bool> AddUrlAsync(string key, string url) { _context.Add(new MappedUrl() { Key = key, Url = url }); return((await _context.SaveChangesAsync()) == 1); }
public async Task DeleteArticleAsync(int id) { using (var context = new StorageDbContext()) { var articleToRemove = await context.Articles.FindAsync(id); context.Articles.Remove(articleToRemove); await context.SaveChangesAsync(); } }
public async Task DeleteUserAsync(int id) { using (var context = new StorageDbContext()) { var userToRemove = await context.Users.FindAsync(id); context.Users.Remove(userToRemove); await context.SaveChangesAsync(); } }
public async Task <User> UpdateUserAsync(int id, User User) { using (var context = new StorageDbContext()) { var userToUpdate = await context.Users.FindAsync(id); MergeUsers(userToUpdate, User); await context.SaveChangesAsync(); } return(User); }
public async Task <User> CreateUserAsync(User User) { User savedUser; using (var context = new StorageDbContext()) { savedUser = context.Users.Add(User); await context.SaveChangesAsync(); } return(savedUser); }
public async Task <int> CreateStorage(string nameParam) { var entityToCreate = new Data.Entities.Storage { Name = nameParam }; using var ctx = new StorageDbContext(); ctx.Storages.Add(entityToCreate); await ctx.SaveChangesAsync(); return(entityToCreate.Id); }
public async Task <Article> UpdateArticleAsync(int id, Article article) { Article articleToUpdate; using (var context = new StorageDbContext()) { articleToUpdate = context.Articles.Include("Author").Include("Comments").Include("Author").Where(a => a.Id == id).FirstOrDefault(); MergeArticles(articleToUpdate, article, context); await context.SaveChangesAsync(); } return(articleToUpdate); }
public async Task <Article> CreateArticleAsync(Article article) { Article savedArticle; using (var context = new StorageDbContext()) { savedArticle = context.Articles.Add(article); await context.SaveChangesAsync(); savedArticle = context.Articles.Include("Author").Include("Comments").Include("Author").Where(a => a.Id == savedArticle.Id).FirstOrDefault(); } return(savedArticle); }
public async Task Handle(IDomainEvent <BoxAggregate, BoxId, BoxCreatedEvent> domainEvent) { var entity = new BoxEntity { AggregateId = domainEvent.AggregateIdentity.Value, Barcode = domainEvent.AggregateEvent.Barcode.Value, Created = domainEvent.Timestamp, Modified = domainEvent.Timestamp }; using (var db = new StorageDbContext(_dbContextOptions)) { await db.AddAsync(entity).ConfigureAwait(false); await db.SaveChangesAsync().ConfigureAwait(false); } }
public async Task CreateATaskAsync(ToDoList task) { await _context.AddAsync(task); await _context.SaveChangesAsync(); }
public virtual async Task SaveChangesAsync() { await context.SaveChangesAsync(); }
public async Task <bool> AddSession(AuthSession session) { _context.Add(session); return(await _context.SaveChangesAsync() == 1); }
public async Task CreateAsync(PresentationConfiguration record) { await _context.AddAsync(record); await _context.SaveChangesAsync(); }