public void Create(PassOneObject obj) { obj.Id = GetNextIdValue(); var creds = (Credentials) obj; using (var db = new PassOneContext()) { var userQuery = from u in db.Users select u; var user = userQuery.ToList().FirstOrDefault(user1 => user1.Id == creds.UserId); var entity = new EntityCredential(new Encryption(user.k, user.v), creds) {User = user}; db.Credentials.Add(entity); db.SaveChanges(); } }
private Credentials ConvertToDomainObject(User user, EntityCredential entity) { var encrypted = new EncryptedCredentials() { Id = entity.Id, UserId = entity.UserId, Website = entity.Website, Url = entity.Url, Username = entity.Username, EmailAddress = entity.Email, Password = entity.Password }; return new Credentials(new Encryption(user.K, user.V), encrypted); }
public PassOneObject RetreiveById(int id) { var db = new PassOneContext(); var query = from u in db.Credentials select u; var creds = query.ToList(); var selected = new EntityCredential(); foreach (var cred in query.Where(cred => cred.Id == id)) selected = cred; var userQuery = from u in db.Users select u; var user = userQuery.ToList().FirstOrDefault(user1 => user1.Id == selected.UserId); return ConvertToDomainObject(new User(user), selected); }