public Application Create(ApplicationViewModel toCreate) { if (string.IsNullOrWhiteSpace(toCreate.Name)) { throw new EntityValidationException("Application Name cannot be blank!"); } var app = new Application() { Name = toCreate.Name, ApplicationUuid = Guid.NewGuid(), EncryptionKey = _encrypter.GenerateKey(), Active = true }; _db.Applications.Add(app); _db.SaveChanges(); return(app); }
protected string GetEncryptionKey(long applicationId) { var application = _db.Applications.First(a => a.ApplicationId == applicationId); if (null == application.EncryptionKey) { application.EncryptionKey = _encrypter.GenerateKey(); _db.SaveChanges(); } return(application.EncryptionKey); }
public Database Create(DatabaseViewModel toCreate) { //TODO: Handle checking if the environment exists ValidationUtils.ValidateViewModel(toCreate); var database = new Database() { EnvironmentId = toCreate.EnvironmentId, Name = toCreate.Name, Type = toCreate.Type, Active = true, EncryptionKey = _encrypter.GenerateKey() }; AddEncryptedValues(database, toCreate); _db.Databases.Add(database); _db.SaveChanges(); return(database.Decrypt(_encrypter)); }