Esempio n. 1
0
 public async Task CreateAsync(CipherDetails cipher)
 {
     cipher.SetNewId();
     using (var connection = new SqlConnection(ConnectionString))
     {
         var results = await connection.ExecuteAsync(
             $"[{Schema}].[CipherDetails_Create]",
             cipher,
             commandType : CommandType.StoredProcedure);
     }
 }
Esempio n. 2
0
        public async Task CreateAsync(CipherDetails cipher, IEnumerable <Guid> collectionIds)
        {
            cipher.SetNewId();
            var objWithCollections = JsonConvert.DeserializeObject <CipherDetailsWithCollections>(
                JsonConvert.SerializeObject(cipher));

            objWithCollections.CollectionIds = collectionIds.ToGuidIdArrayTVP();
            using (var connection = new SqlConnection(ConnectionString))
            {
                var results = await connection.ExecuteAsync(
                    $"[{Schema}].[CipherDetails_CreateWithCollections]",
                    objWithCollections,
                    commandType : CommandType.StoredProcedure);
            }
        }
Esempio n. 3
0
        private async Task <CipherDetails> CreateAsyncReturnCipher(CipherDetails cipher)
        {
            cipher.SetNewId();
            using (var scope = ServiceScopeFactory.CreateScope())
            {
                var dbContext = GetDatabaseContext(scope);
                var userIdKey = $"\"{cipher.UserId}\"";
                cipher.UserId    = cipher.OrganizationId.HasValue ? null : cipher.UserId;
                cipher.Favorites = cipher.Favorite ?
                                   $"{{{userIdKey}:true}}" :
                                   null;
                cipher.Folders = cipher.FolderId.HasValue ?
                                 $"{{{userIdKey}:\"{cipher.FolderId}\"}}" :
                                 null;
                var entity = Mapper.Map <EfModel.Cipher>((TableModel.Cipher)cipher);
                await dbContext.AddAsync(entity);

                await dbContext.SaveChangesAsync();
            }
            await UserBumpAccountRevisionDateByCipherId(cipher);

            return(cipher);
        }